Getting error: The content of element type “web-app” must match,

前端 未结 3 1021
青春惊慌失措
青春惊慌失措 2020-12-05 09:52

When I build my project in Eclipse Helios Service Release 2, I get an error in my web.xml. Please suggest what I have to do for this. In my project I am using D

相关标签:
3条回答
  • 2020-12-05 09:57

    I have the same issue when I integrate spring to struts2 in Eclipse. After some testing, I found it's the problem of tag's order in web.xml file. The following file has the error

    <!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>Archetype Created Web Application</display-name>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <filter>
            <filter-name>struts</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
            <init-param>
                <param-name>struts.devMode</param-name>
                <param-value>true</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>struts</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    </web-app>
    

    If I changed the order to

    <!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>Archetype Created Web Application</display-name>
        <filter>
            <filter-name>struts</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
            <init-param>
                <param-name>struts.devMode</param-name>
                <param-value>true</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>struts</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-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>
    

    The error will be eliminated.

    Hope this will be helpful to the people who encounter the same problem.

    0 讨论(0)
  • 2020-12-05 10:03

    If anyone's interested I received the same exception for error-page. This node needs to go after servlet, but before servlet-mapping.

    0 讨论(0)
  • 2020-12-05 10:20

    The error message tells you in detail in what order the elements are supposed to be placed and how many of them are allowed. In other words, the ordering or amount of the elements inside the <web-app> of your web.xml is incorrect. For example, as per the error message, <servlet> needs to go before <servlet-mapping>. The ? suffix means that there may be zero or one of them. The * suffix means that there may be zero or many of them.

    So, the example below is invalid:

    <servlet>...</servlet>
    <servlet-mapping>...</servlet-mapping>
    
    <servlet>...</servlet>
    <servlet-mapping>...</servlet-mapping>
    
    <servlet>...</servlet>
    <servlet-mapping>...</servlet-mapping>
    

    While the example below is valid:

    <servlet>...</servlet>
    <servlet>...</servlet>
    <servlet>...</servlet>
    
    <servlet-mapping>...</servlet-mapping>
    <servlet-mapping>...</servlet-mapping>
    <servlet-mapping>...</servlet-mapping>
    
    0 讨论(0)
提交回复
热议问题