4

I am getting an error in my GWT application being developed in Eclipse. It's in the web.xml file. Here's 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*)".

I have seen numerous posts about this and the problem is the order of the elements of the file, but that fix doesn't work for me (I have also tried putting all the <servlet-mapping> tags right after the corresponding <servlet>, it did not work either)

My web.xml file :

<?xml version="1.0" encoding="UTF-8"?>
<!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>

  <servlet>
    <servlet-name>dispatch</servlet-name>
    <servlet-class>com.yachtcloser.server.DispatchServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>upload</servlet-name>
    <servlet-class>com.yachtcloser.server.UploadServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet> 

  <servlet>
    <servlet-name>download</servlet-name>
    <servlet-class>com.yachtcloser.server.DownloadServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>login</servlet-name>
    <servlet-class>com.yachtcloser.server.LoginServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>dispatch</servlet-name>
    <url-pattern>/dispatch.do</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>upload</servlet-name>
    <url-pattern>/upload.do</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>download</servlet-name>
    <url-pattern>/download.do</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/login.do</url-pattern>
  </servlet-mapping>

  <!-- Default page to serve -->
  <welcome-file-list>
    <welcome-file>Yc.html</welcome-file>
  </welcome-file-list>

</web-app>

Are there any other ways of tracking this error; other files that are linked to this?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
HeelToeHero
  • 113
  • 1
  • 1
  • 6

5 Answers5

15

well, as per new format of DTD web-app tag might contains following tags. <!ELEMENT web-app (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*)>

above mentioned icon, display-name, description, distributable....etc are in the same order as they have mentioned in the DTD file.

e.g. if you put description tag before display-name it gives error.

Jay Gohel
  • 151
  • 1
  • 5
  • 2
    I had this problem, and thanks to you I solved, the problem was in a bad order of elements... – Marcx Jun 26 '13 at 09:33
  • Cut copy paste is not a permanent solution, i gone for the above one. it worked, just re arranged the order of servlet mapping and listeners. It solved. – srinivas Jul 30 '15 at 03:35
7

I deleted the file and pasted the text from the old one into a new file with the same name and now there's no errors.

HeelToeHero
  • 113
  • 1
  • 1
  • 6
2

Just for a reference: A SelectAll->Cut->Save->Paste->Save also fixes the problem. Probably there is a line ending character issue.

Aram Paronikyan
  • 1,598
  • 17
  • 22
1

I followed the suggestion for "copy all" - "cut" - "paste" - "save" and this seemed to clear up the message. 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.

Bill H
  • 51
  • 1
  • 1
    In Eclipse, you can also re-format the code using CTRL+SHIFT+F (or by going to source > format). That should also clear out any formatting issues. – vdwijngaert Mar 12 '14 at 15:59
-1

The error itself gives you the clue. The order of the elements in your web.xml should follow the order specified in the error.

<displayname>
</displayname>
<description>
</description>

....... like this the elements should be in order as it says in the error.

Cnu
  • 11
  • 2
  • This answer seems irrelevant, the quesion was asked 3 years ago and the issue seems to be related to line endings or something similar. Not the order of the elements. – Scriptable Jan 25 '15 at 18:48
  • it's relevant, rather typing the whole web.xml. I have just given a view. I had the same issue, while declaring content-param, I wrote them after servlet-mapping, so I got this error. When changed the order, error went away. So It could be a possible reason. – Cnu Jan 25 '15 at 20:09
  • FYI, see the very first answer of this post. – Cnu Jan 25 '15 at 20:23
  • So that answer has alreay been given, so its not needed again :) – Scriptable Jan 25 '15 at 20:26
  • I posted my experience, I though it would be use full for some one. But you are saying it's not relevant... – Cnu Jan 25 '15 at 20:30
  • I was merely saying my opinion that it doesnt seem useful, if you think it is useful then leave it there mate, just a suggestion as part of the review process. – Scriptable Jan 25 '15 at 20:32