Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

web.xml is quite perplexing 1

Status
Not open for further replies.

plasante

Programmer
Oct 6, 2003
4
CA
I'm running Apache Tomcat/4.1.30 on Windows XP and I have the following problem:

This web.xml works fine:

<web-app>
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>

This one also works fine:

<web-app>
<description>MySQL Test App</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>

But this one generates an error when I start Tomcat:

<web-app>
<description>MySQL Test App</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>

Here is the error:

1-Aug-2004 8:02:28 PM org.apache.commons.digester.Digester error
SEVERE: Parse Error at line 23 column 11: The content of element type "web-app"
must match "(icon?,display-name?,description?,distributable?,context-param*,filt
er*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-map
ping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,sec
urity-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref
*)".

Any suggestion as to what is causing the problem?
 
According to DTD for web.xml,
Code:
<!ELEMENT web-app 
(icon?, display-name?, description?, distributable?,
context-param*, filter*, filter-mapping*, listener*, [COLOR=red]servlet*[/color], [COLOR=red]servlet-mapping*[/color], session-config?, mime-mapping*, welcome-file-list?, error-page*, taglib*, resource-env-ref*, [COLOR=red]resource-ref*[/color], security-constraint*, login-config?, security-role*, env-entry*, ejb-ref*,  ejb-local-ref*)>

sequence of element does matter and

<servlet> should goes before
<servlet-mapping> which should goes before
<resource-ref>

The problem of your later config is that the order of the elements are violating the dtd, which is the error complaining about.
 
GeeWhizz. Thanks. It has solved my problem.
Here is my new web.xml

<web-app>

<description>MySQL Test App</description>

<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>

<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

</web-app>

I can stop pulling my hair off now :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top