aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Order of DD elements within <servlet> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Order of DD elements within <servlet>" Watch "Order of DD elements within <servlet>" New topic
Author

Order of DD elements within <servlet>

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Howdy Ranchers!

I am reading Charles Lyons book, chapter 9, question 12:

Charles Lyons wrote:"Place the following declarations in the order they should appear in a servlet declaration:"

and there is a bunch of DD <servlet> sub-elements which you need to put in "order".

I know that there is a word "should" and not "must", but what does this "should" means? The order of element definition in XSD?
Is the order of <servlet> DD sub elements really important?

I am reading Servlet 3 specification from November 2009 which states:
14.4 Deployment Descriptor Diagram - 1.web-app Element wrote:(...) All sub elements under this element [web-app - editorial note] can be in an arbitrary order.


So it's clear for <web-app> sub elements. But there is no such information about <servlet> sub elements.

So, can the container force some particular order of the definitions? What do you think the Author (Charles Lyons) had in his mind while writing "(...) order they should apprear in (...)"?

Cheers!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61432
    
  67

This has changed from version to version.

If you get it wrong, you'll certainly find out!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Thanks Bear for fast answer.

Before posting, I've tested it in Tomcat 7, and there were no problem with the below order:



which (according to the Charles book) is not correct, because:
- the <display-name> should be before <servlet-name>,
- the <servlet-class> should be before <init-param>.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61432
    
  67

Was the Lyons book written with Servlets 3.0 in mind? Unlikely. Expecting it to be prescient with regards to yet-to-be released versions of Servlets is a little unreasonable, don't you think?
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Ok, you are right. I should test it using Tomcat 6. Which I did right now, and the result is the same - no difference with the order within <servlet> element.

This post is not about accusing Charles what he writes and saying that it's wrong, so please don't take it that way - this is definitely not the purpose of this topic.
It's about getting know what the world "should" means in the book's question (as stated in the first post) and what the situation looks for the present Servlets 3.0.

If the order of the DD <servlet> sub elements was relevant for the Servlet version the book was written for, than fine. But I still think that the question like "can the container force some particular order of the definitions?" is still relevant.

And about Servlets 3.0 in Charles book... I'm holding the Second edition which is subtitled as "with Java EE 6 preview". And in fact there are some additional information about Servlets 3.0 like p. 218 (the very same chapter I was referring to).

Cheers!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61432
    
  67

If the book was written against Servlets 2.3, that version used an XML DTD rather than an XML Schema for validation. DTDs aren;t as expressive as Schemas, so the rules were a bit more strict.

In regards to "should" versus "must", I'd say they are interchangeable in the context they are being used. As in "you should order things this way in order to avoid causing the server to internally hemorrhage".
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Thank you Bear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Order of DD elements within <servlet>