Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mahalakshmi Chandru
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Mahalakshmi Chandru
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Woww...that calrifies my doubt...thanks for your timely response
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic