aspose file tools*
The moose likes Servlets and the fly likes Order of elements in the DD- web.xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Order of elements in the DD- web.xml file" Watch "Order of elements in the DD- web.xml file" New topic
Author

Order of elements in the DD- web.xml file

Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
I believe that the order of tage in the DD web.xml is order specific.
I read somewhere that the following order be followed: filter, listeners, servlets and their mapping, session-config, welcome-file-list etc

But, surprisingly the listener tag is working fine even ferore servlet and server-mapping elemnets and also after them. How can this be true?

Any help shall be highly appreciated.
Mukesh Mittal
Ranch Hand

Joined: Jan 13, 2006
Posts: 31
Deployment descriptor elements are in order. For version 2.3, order is

<!ELEMENT web-app (icon?, display-name?, description?,
distributable?, context-param*, filter*, filter-mapping*,
listener*, servlet*, servlet-mapping*, session-config?, mimemapping*,
welcome-file-list?, error-page*, taglib*, resourceenv-
ref*, resource-ref*, security-constraint*, login-config?,
security-role*, env-entry*, ejb-ref*, ejb-local-ref*)>

Are you validating your descriptor file against dtd file?
If you use any IDE and mentioned your listener element after servlet element, you will see error message.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

It also depends upon what version of the Servlet Specification your deployment descriptor is using. The ordering rules of elements using the Servlets 2.3 DTD will be different than using the Servlets 2.4 XML Schema.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Bear/Mukesh,
Thanks for posting your comments.

Mukesh, I have also tried the same web.xml file with Eclipse 3.2 with a Tomcat plugin. But still, I don't get to see any error message on the console.

Bear, I'm, using jakarta-tomcat-5.0.28 which I believe implements Servlet 2.4 Spec.

I still have no clue that even if I move the listener tag after servlet definition and mapping, I don't get to see any error message.

Thanks,
Reema
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Originally posted by Reema Patel:
Bear, I'm, using jakarta-tomcat-5.0.28 which I believe implements Servlet 2.4 Spec.


It can, but that's moot if you continue to use the 2.3 DTD in your deployment descriptor.
Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Hi Bear,
Thanks for the post.

I belive that the DTD description goes in the beginning of a standard DD-web.xml file. Following is an element from the web.xml file I'm using:



I think this is using Servlet spec 2.3 and that might be the reason I'm not getting to see any error on the console when I put a listener element before a servlet/servlet-mapping element.

I also tried to replace the digit- 3 with 4, but it throws the following error on the console when Tomcat is started:


Could you please guide me on this.

Regards,
Reema
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

If you read my first post in this topic, you will have noted that Servlets 2.4 does not use a DTD; it uses an XML Schema.

You can find the correct syntax in the Servlet Specification. You do have it handy on your desk, don't you?
Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Hi Bear,
Thanks for posting again!


If you read my first post in this topic, you will have noted that Servlets 2.4 does not use a DTD; it uses an XML Schema

What's the difference between a DTD and an XML schema.My apologies, if i'm sounding too novice here.

In short, how can I get to see the error message on the console window if I precede servlet or servlet-mapping element(s) before the lostener element? I'm using jakarta-tomcat-5.0.28 and, have already posted the contents of web.xml file?

Any help shall be highly appreciated.
Thanks,
Reema
Mukesh Mittal
Ranch Hand

Joined: Jan 13, 2006
Posts: 31
I think everything is depends on your servlet conatiner. I am using websphere and getting error with servlet 2.3

If you move your listener element after the servlet then you will get error message.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Originally posted by Reema Patel:

What's the difference between a DTD and an XML schema.


It might be helpful if you could do some research on your own.

DTD

XML Schema
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Originally posted by Reema Patel:

What's the difference between a DTD and an XML schema.


It might be helpful if you could do some research on your own.

DTD

XML Schema
 
 
subject: Order of elements in the DD- web.xml file