element filtername is not allowed here

背景:最近在使用IntellijIdea2016搭建项目的时候,在web.xml中出现了element filtername is not allowed here的错误。

原因:总体来讲,后来查出来的原因是web.xml头部的配置有错误的,当然网上也有说各种原因的。

解决办法:更换web.xml头部(代码中前4行)

我目前的配置如下,如果遇到该问题可以参考如下:

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         id="WebApp_ID" version="3.0">
    <!-- 配置Spring配置文件路径 -->
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
        classpath:applicationContext.xml
      </param-value>
    </context-param>
    <!-- 配置Spring上下文监听器 -->
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- 配置Spring字符编码过滤器 -->
    <filter>
      <filter-name>encodingFilter</filter-name>
      <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
      <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
      </init-param>
      <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
      </init-param>
    </filter>
    <filter-mapping>
      <filter-name>encodingFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- 配置log4j配置文件路径、检测日志配置文件变化 -->
    <context-param>
      <param-name>log4jConfigLocation</param-name>
      <param-value>classpath:log4j.properties</param-value>
      <param-name>log4jRefreshInterval</param-name>
      <param-value>30000</param-value>
    </context-param>
    <!-- 配置Log4j监听器 -->
    <listener>
      <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <!-- 首页 -->
    <welcome-file-list>
      <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>

    <!-- 错误页 -->
    <error-page>
      <error-code>404</error-code>
      <location>/error/404.jsp</location>
    </error-page>
    <error-page>
      <error-code>500</error-code>
      <location>/error/500.jsp</location>
    </error-page>
  </web-app>

资料参考:http://stackoverflow.com/questions/17563756/element-listener-class-not-allowed-in-my-web-xml

http://blog.csdn.net/cor_twi/article/details/51063541

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章