Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Lifecyle

 
Micheal John
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pls suggest, whether the following steps are correct(in order), which will be foundation for my basics in servlet.

1. Container reads the web.xml (consider only one servlet mapping with init parameter and context-parameter, which is outside the servlet)(Whether ServletConfig instance will be created first or ServletContext instance will be created first???)
2. Reads the init-param for that particular servlet
3. creates new ServletConfig instance for that servlet
4. creates name/value pair for that servlet
5. gives the ServletConfig references to the name/value init parameter
6. creates a new instance for that servlet (constructor will be run..at this stage it is an ordinary object. right??)
7. calls init(ServletConfig) method, whicg will call the init() (now the ordinary object becomes servlet..right??)
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether ServletConfig instance will be created first or ServletContext instance will be created first?

Here's something from Servlet Spec. 2.4 --Page 78
When a web application is deployed into a container, the following steps must be performed, in this order, before the web application begins processing client requests.
� Instantiate an instance of each event listener identified by a <listener> element in the deployment descriptor.
� For instantiated listener instances that implement ServletContextListener, call the contextInitialized() method.
� Instantiate an instance of each filter identified by a <filter> element in the deployment descriptor and call each filter instance�s init() method.
� Instantiate an instance of each servlet identified by a <servlet> element that includes a <load-on-startup> element in the order defined by the load-on-startup element values, and call each servlet instance�s init() method.
 
Roger Stratus
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael
Hope this answers your question. (i have not included details about the listeners and filters since you mentioned you are still learning the basics )

1) Container reads the Deployemnt Descriptor <context-parameter> and <servlet> <init-parameter>
2) Creates a new ServletContext for application.
3) Creates name/value pairs for each context parameter
4) Assigns the ServletContext to the name/value
5) Creates a new ServletConfig instance for the servlet
6) Container creates name/value pairs for each init-paramter
7) Container gives the ServletConfig reference to the name/value init parameters
8) Container creates a instance of servlet
9) Container calls the init(ServletConfig) method

PS. All the above tasks are carried our by the Container
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic