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

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