aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Clarification in the order in which the DD is read by the container!! 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 "Clarification in the order in which the DD is read by the container!!" Watch "Clarification in the order in which the DD is read by the container!!" New topic
Author

Clarification in the order in which the DD is read by the container!!

Mahalakshmi Chandru
Ranch Hand

Joined: Feb 26, 2009
Posts: 48
Hi all,
I have a doubt reg the order in which the 'DD' will be read by the sevlet contaner. First, the container will create a Servletconfig object depending upon the init params, and then it creates the name/value pair which will be given reference of the servletconfig object.

Then when the container calls the servlets init() method with the servletconfig obj as a parameter. My doubt here is if the <init-param> comes at the end of the DD, how will the servlets get the init values properly, because the<servlet-class> tag is before the <init-param> tag. Please clarify whether the order in which the <init-param> matters in DD. When i cheked it by changing the order, it didnt affect. But still eager to know how the servlet gets the init values eventhough theuy are at last.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Lets see a sample web.xml with a servlet configuration

Now here the whole servlet tag encloses this servlet declaration, so the container will read the whole tag and then call the init method of the servlet. When the container encounters the servlet-class tag, it will not go ahead and instantiate and call init on the servlet. When the container reads the servlet-class tag, it doesn't have enough information to call the init method as it knows that there might be init parameters after that...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Mahalakshmi Chandru
Ranch Hand

Joined: Feb 26, 2009
Posts: 48
Ankit,
This is in the case of init parameters for 'Servlet config'. Does the init() method takes only the'servletconfig' as an argument? If we use 'servlet-context' instead of 'servlet-config', how the flow will be. When the servlets init() method will be called ? and if so, what will be the argument? I have attached a sample web.xml.



Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

The answer is simple, before reading information about servlets, first the container needs to create the ServletContext object, so it will read the context parameters, create a ServletContext object and then proceed to creating servlets. I don't know the exact order in which the container starts an application (i.e. maybe it creates listeners before filters or maybe not), but whatever order the container follows has nothing to do with the order in which you declare different types of elements here

[Note: this is not to be confused with the order of similar elements for example if there are two ServletContextListener, then their order in the web.xml makes a difference]
Mahalakshmi Chandru
Ranch Hand

Joined: Feb 26, 2009
Posts: 48
Woww...that calrifies my doubt...thanks for your timely response
 
jQuery in Action, 2nd edition
 
subject: Clarification in the order in which the DD is read by the container!!