欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Element filtername is not allowed here-web.xml version="3.0"-intellij idea

程序员文章站 2022-05-08 22:17:39
...

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

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

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

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

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
  3. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  4. id="WebApp_ID" version="3.0">
  5. <!-- 配置Spring配置文件路径 -->
  6. <context-param>
  7. <param-name>contextConfigLocation</param-name>
  8. <param-value>
  9. classpath:applicationContext.xml
  10. </param-value>
  11. </context-param>
  12. <!-- 配置Spring上下文监听器 -->
  13. <listener>
  14. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  15. </listener>
  16. <!-- 配置Spring字符编码过滤器 -->
  17. <filter>
  18. <filter-name>encodingFilter</filter-name>
  19. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  20. <init-param>
  21. <param-name>encoding</param-name>
  22. <param-value>UTF-8</param-value>
  23. </init-param>
  24. <init-param>
  25. <param-name>forceEncoding</param-name>
  26. <param-value>true</param-value>
  27. </init-param>
  28. </filter>
  29. <filter-mapping>
  30. <filter-name>encodingFilter</filter-name>
  31. <url-pattern>/*</url-pattern>
  32. </filter-mapping>
  33. <!-- 配置log4j配置文件路径、检测日志配置文件变化 -->
  34. <context-param>
  35. <param-name>log4jConfigLocation</param-name>
  36. <param-value>classpath:log4j.properties</param-value>
  37. <param-name>log4jRefreshInterval</param-name>
  38. <param-value>30000</param-value>
  39. </context-param>
  40. <!-- 配置Log4j监听器 -->
  41. <listener>
  42. <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  43. </listener>
  44. <!-- 首页 -->
  45. <welcome-file-list>
  46. <welcome-file>/index.jsp</welcome-file>
  47. </welcome-file-list>
  48. <!-- 错误页 -->
  49. <error-page>
  50. <error-code>404</error-code>
  51. <location>/error/404.jsp</location>
  52. </error-page>
  53. <error-page>
  54. <error-code>500</error-code>
  55. <location>/error/500.jsp</location>
  56. </error-page>
  57. </web-app>

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

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