The content of element type "..." must match in web.xml
Asked Answered
F

13

44

I have a problem with my web.xml file. The error:

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*)".

However, my web.xml file is in the order what error say.

Here is my 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>Archetype Created Web Application</display-name>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    </context-param>
      
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
        <description></description>
    </context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
      
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

</web-app>

I use WebLogic 10.3.4. Any idea about the problem?

Flanna answered 18/9, 2012 at 7:46 Comment(7)
Yeah, the order of this file screws me over regularly. According to the DTD snippet you posted, the welcome-file-list should appear after the servlet and servlet mappings. Try that.Germinant
No, it is not the problem. the order of the tags perfectly fits to the DTD.Flanna
Sure? the DTD states that the welcome-file-list comes after servlet-mapping - it's later in the comma-separated list of elements.Germinant
yes i am sure. i changed it. i have still same problem.Flanna
Well I'm at a loss then - that's the only thing I can see wrong with it :/Germinant
Thank you for your reply. the error completely meaningless.Flanna
possible duplicate of web app web.xml errorObscurant
A
83

One very simple solution which solves my problem.

Change the schema reference from

<!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></web-app>

to this

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
         version="2.5" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
         // ...
         // your all content goes here

</web-app>
Accord answered 6/11, 2014 at 11:19 Comment(1)
Changing the <!DOCTYPE ... line to <?xml ... was enough for me.Supersedure
C
22

I had the same problem in Eclipse, after re-order tags as DTD, the error goes way. You may also try to restart Eclipse.

Cyrillus answered 4/8, 2013 at 0:28 Comment(2)
What do you mean re-order tags as DTD?Lowdown
Reordering the tag means arranging the tags( like icon, display-name, servlet, servlet-mapping) in the way that web.xml specifies. You can see the order in the help message which comes when you mouse over the error in eclipse.Noddle
N
8

I observed that DTD at Web.xml required an specific order for elements servlet, servlet-mapping, etc.

So, I started adding each element from Design View of XML file at ECLIPSE.

It works!. You can build your XML file in a way it likes to DTD.

Nappe answered 14/12, 2014 at 23:37 Comment(0)
C
7

I just removed <!DOCTYPE .. > tag and it worked for me. Actually I don't know how much important..

Communion answered 2/8, 2016 at 10:59 Comment(0)
A
4

I followed someone's suggestion for "copy all" - "cut" - "paste" - "save" and this seemed to clear up the message. Comparing the before and after files, I found that in the "pasted" version all tabs had been converted to spaces. So it seems that the web.xml validator in Eclipse does not like tabs.

Apicella answered 12/3, 2014 at 15:31 Comment(0)
V
2

rearrange your code like this...

<web-app>
  <display-name>Archetype Created Web Application</display-name>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

 <context-param>   
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
  </context-param>

  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
    <description></description>>
  </context-param>

  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
 <servlet-mapping>
   <servlet-name>Faces Servlet</servlet-name>
   <url-pattern>/faces/*</url-pattern>
 </servlet-mapping>

and if you have more servlet then define your servlet above the mapping then map your servlet after that.

Villenage answered 19/12, 2013 at 11:53 Comment(0)
S
2

Finally i resolved this issue by configuring servlet and servlet-mapping by using design view in eclipse instead of typing directly in the web.xml in source view. Hope this helps.

Systemize answered 5/4, 2018 at 11:59 Comment(0)
K
2

This part was removed and errors were solved.

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"  "http://java.sun.com/dtd/web-app_2_3.dtd" >
Korten answered 20/5, 2018 at 14:53 Comment(0)
P
1

If you are dealing with this same issue and find nothing at all wrong with web.xml syntax, I recommend doing the following: "cut (all content within web.xml)", "paste to notepad" - "copy from notepad" - "paste back into web.xml" - "and finally save web.xml". Got to love those invisible characters, tabs, etc.

Patricio answered 29/9, 2014 at 21:51 Comment(1)
That worked for me, wondering why: web.xml last change was 16 months so why the sudden eclipse error ?Tiphane
P
1

Just don't forget to save the file when trying the above solutions. The error went away in my case after using the latest schema descriptor and saving :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">

    <!-- your content here -->

</web-app>`
Pickmeup answered 11/9, 2018 at 1:52 Comment(0)
H
0

I just removed the DOCTYPE and restarted Eclipse. It worked. Do try

Hord answered 20/8, 2021 at 6:6 Comment(0)
R
0

Instead of using "xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd""

use

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

Rania answered 23/11, 2021 at 7:9 Comment(1)
Welcome to Stack Overflow! While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.Milamilady
C
0

Just order the tags, as mentioned in the error message in web.xml file.

Order like this:

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
    <servlet-name>abc</servlet-name>
    <servlet-class>ServletTest</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>pqr</servlet-name>
    <servlet-class>SqServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>abc</servlet-name>
    <url-pattern>/add</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>pqr</servlet-name>
    <url-pattern>/sq</url-pattern>
  </servlet-mapping>
</web-app>

Not like this:

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
    <servlet-name>abc</servlet-name>
    <servlet-class>ServletTest</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>abc</servlet-name>
    <url-pattern>/add</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>pqr</servlet-name>
    <servlet-class>SqServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>pqr</servlet-name>
    <url-pattern>/sq</url-pattern>
  </servlet-mapping>
</web-app>
Cayes answered 5/5 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.