欢迎光临
感受代码之美

解决web.xml报错The content of element type “web-app” must match(正解)

IntelliJ IDEA编辑器显示web.xml红叉,内容如下

The content of element type “web-app” must match “(icon ,display-

name ,description ,distributable ,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-

mapping*,session-config ,mime-mapping*,welcome-file-list ,error-page*,taglib*,resource-env-

ref*,resource-ref*,security-constraint*,login-config ,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)”.

- No grammar constraints (DTD or XML schema) detected for the document.

出错原因是web.xml标签顺序有问题,比如下面的顺序就是正确的:

<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Agreport</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:ureport-console-context.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>ureportServlet</servlet-name>
        <servlet-class>com.bstek.ureport.console.UReportServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>ureportServlet</servlet-name>
        <url-pattern>/ureport/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

而下面的顺序就会提示红叉:

<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Agreport</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:ureport-console-context.xml</param-value>
    </context-param>



    <servlet>
        <servlet-name>ureportServlet</servlet-name>
        <servlet-class>com.bstek.ureport.console.UReportServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>ureportServlet</servlet-name>
        <url-pattern>/ureport/*</url-pattern>
    </servlet-mapping>

    <!--调正顺序-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

转载请注明来源:四个空格 » 解决web.xml报错The content of element type “web-app” must match(正解)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址