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

洼地云 tuoyidashi.png

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>

赞(0)
未经允许禁止转载:优米格 » 解决web.xml报错The content of element type “web-app” must match(正解)

评论 抢沙发

合作&反馈&投稿

商务合作、问题反馈、投稿,欢迎联系

广告合作侵权联系

登录

找回密码

注册