• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Question regarding deployment descripter

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a question regarding the deployment descriptor. I found such questions in the mock exams:
<web-app>
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>com.test.Test</servlet-class>
</servlet>
<listener>
<listener-class>com.test.Listener</listener-class>
</listener>
</web-app>
And the question is asking whether this is valid. I thought this is valid, but the answer says no because the order of <listener> and <servlet> is not correct (<listener> should be before <servler> ). I am not very familiar with XML, so I am not sure whether this order really matters (the DTD does show listener before servlet, but I still doubt). Does anyone know where in the SUN's specification that indicates this ordering specifically or this is just the rule in XML, whatever attribute appears first in the DTD for an element, it should appear in the XML document first for that element also.
Many thanks.
Ming
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, Sun doesn't specify. It's actually up to the validation rules built into the XML Parser that your implementation uses. By strict rules, elements must be order as they appear in the DTD. Tomcat uses a parser that follows the strict rules. Other servers may not but, it is always best to ensure full compatablity of anything you develop to follow the strict rules.
------------------
I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Carl,
What do mean by Sun does not specify? Did you want to say that Sun does not specify in DTD? The reason I am asking this is, <login-config> should appear after <security-constraint> (according to Oreilly's book on Servlet programming by Jason Hunter), but the dtd provided by Sun does not specify this fact either. I think one should try putting <servlet> tag before <listener> tag and see if it works.
My observation about Sun's dtd is that it lists all the tags alphavetically and that is why <listener> comes before <servlet>
The question that the given web.xml is correct or not still remains a question. I think the order should not matter. This is because the Listener classes apply to context and/or session and both are application scoped and hence accessible by any servlet. Since Listener apply to the web-app in general its placement in web.xml should not matter.
I would love to see more comments
Chintan
[This message has been edited by Chintan Rajyaguru (edited December 20, 2001).]
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. I would agree with Carl.
Following is the quote from section "SRV.13.2 - Rules for Processing the Deployment Descriptor" in "Chapter SRV.13 - Deployment Descriptor" of Java Servlet Specification Version 2.3
"It is recommended, but not required, that web containers and tools validate deployment descriptors against DTD document for structural correctness."
This supports Carl's statement -
"No, Sun doesn't specify"
2. I would like to rectify Chintan's statement -
"My observation about Sun's dtd is that it lists all the tags alphavetically and that is why <listener> comes before <servlet>"
No, in Sun's DTD, as in servlet 2.3 spec, tags are not listed alphabetically.
If you observe DTD carefully
a) security-role comes before env-entry
b) icon comes before display-name
c)distributable comes before context-param
Hope this helps
------------------
Harpreet S Hira
Sun Certified Java2 Programmer
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chintan Rajyaguru:
What do mean by Sun does not specify? Did you want to say that Sun does not specify in DTD? The reason I am asking this is, <login-config> should appear after <security-constraint> (according to Oreilly's book on Servlet programming by Jason Hunter), but the dtd provided by Sun does not specify this fact either. I think one should try putting <servlet> tag before <listener> tag and see if it works.


It is not a requirement. However, some application servers choose to be strict about the order of the elements and Tomcat is one of them.

[This message has been edited by Allan Moster (edited December 21, 2001).]
 
Chintan Rajyaguru
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Harpreet,
I checked http://java.sun.com/dtd/web-app_2_3.dtd. The list of elements under web-app element is NOT in any order. However, the order in which elements appear in the dtd is alphabetically ordered.
Allan,
what you are saying makes sense because if there was such a requirement, the specification would specify it.
Chintan
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is unlikely that "structural correctness" as specified in SRV 13.2 includes the order of the sub-elements.
For example:
<!ELEMENT context-param (param-name, param-value, description?) >
and
<!ELEMENT security-role (description?, role-name) >
Why the "description" sub-element, which itself is optional, sometimes placed in the first position, even before the required sub-element??
The order seems a little arbitary and there is no reason to regard the order as specified is more "structurally correct".
If some container providers choose to follow this "strictly", we need to find out the logic behind it.
 
Ranch Hand
Posts: 2379
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chintan, roughly to say DTD is the place where the definition of what an XML document can do is defined. Like how many elements, in what order, what will be the attributes.
So here if the above DTD tells listener element is to be placed b4 servlet element, then that's the order. Some parsers may not worry abt the order of elements but this the standard rule and followed by the Tomcat....

------------------
Muhammad Ashikuzzaman (Fahim)
Sun Certified Programmer for the Java� 2 Platform
--When you learn something, learn it by heart!
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic