• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

org.xml.sax. SAXParseException: Element type "web-app" must be declared.

 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my web.xml as given in HFSJ.

<web-app xmlns = "http://java.sun.com/xml/ns/j2ee"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version = "2.4">
<servlet>
<servlet-name>Listener</servlet-name>
<servlet-class>com.example.ListenerTester
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Listener</servlet-name>
<url-pattern>/Listen.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>breed</param-name>
<param-value>Great Its Done !</param-value>
</context-param>
<listener>
<listener-class>com.example.MyServletContextListener
</listener-class>
</listener>
</web-app>

I am using Tomcat 4.0. But when I am starting tomcat, I am geting an exception like
org.xml.sax.SAXParseException: Element type "web-app" must be declared.[

Can anyone please tell me where I am wrong?

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat 4 does not support version 2.4 of web.xml.
Either use Tomcat 5, or change your web.xml to comply to the 2.3 spec
 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have changed my web.xml to like this (to comply with 2.3)

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>Listener</servlet-name>
<servlet-class>com.example.ListenerTester</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Listener</servlet-name>
<url-pattern>/Listen.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>breed</param-name>
<param-value>Great Its Done !</param-value>
</context-param>
<listener>
<listener-class>com.example.MyServletContextListener</listener-class>
</listener>
</web-app>

but now Its giving me different exception saying ....

org.xml.sax.SAXParseException: 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*)".

Thanks
 
Janhavi Namshikar
Ranch Hand
Posts: 85
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try changing the dtd to this

http://java.sun.com/dtd/web-app_2_3.dtd

Add this part

<context-param>
<param-name>breed</param-name>
<param-value>Great Its Done !</param-value>
</context-param>
<listener>
<listener-class>com.example.MyServletContextListener</listener-class>
</listener>

before this

<servlet>
<servlet-name>Listener</servlet-name>
<servlet-class>com.example.ListenerTester</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Listener</servlet-name>
<url-pattern>/Listen.do</url-pattern>
</servlet-mapping>


should be in the order as it is defined in the dtd.

See if it helps.
[ July 14, 2006: Message edited by: Janhavi Namshikar ]
 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot to both of u !
Its working now.

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imran,
if you're studying for SCWCD, I recommend you to download Tomcat 5.0 (which supports Servlet 2.4 and JSP 2.0) and use version 2.4 of web.xml.

Good luck.
 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for ur suggestion. I will do that..
Further plz send me any mock exam simulator or any other material related to SCWCD.......

Thank u so much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic