• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Introduction

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
my name is rosy I Want Servlet Life Cycle Process.Can you provide these details.

thank you

rosy

 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Google is your friend.

And welcome to the Ranch.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SERVLET LIFE CYCLE

At server start-up

When you start the web-server[like tomcat] then web-container will be started and following tasks will occur on start-up:

1.Container reads the data from web.xml[using SAX parser] and stores that data in the main-memory.[Jvm]
2.Container creates the Servlet-context object and initializes the Servlet-context object with context parameters specified in web.xml.
3.Thread pool will be created by the container.
4.All the Filters and Listeners will be initialized.
5.container checks whether any servlet is configured with <load-on-startup> tag the that servlet will be initialized.

while initializing any servlet at start-up following events occur:
1.Servlet class will be loaded.
2.Servlet instance will be created by calling the default Constructor.
3.Container creates the Servlet-config object and initializes the Servlet-config object with context parameters specified in web.xml.
4.Container calls the init() method by passing Servlet-config as a parameter.
NOTE: Anyhow servlet is initialized above said tasks will happen at each servlet start-up.

WHEN you SEND THE FIRST REQUEST TO A SERVLET FOLLWING EVENTS HAPPEN:

1.Container picks the thread from the pool and assigns the request processing.
2.Now thread will start the request processing as follows:
(A)It creates the HttpServletRequest object and initializes the HttpServletRequest object with the data coming from client(like request parameters,request headers,request cookies etc..)
(B) creates the HttpServletResponse object and initializes the HttpServletResponse object with IO Stream.
(C)calls the service() method of servlet with request and response object as parameters.
(D)Once the service method execution is done then stream associated with response object will be taken and flushed to the client over network.

3.Container returns the thread to the pool after request processing is finished.

AT THE SHUTDOWN OF SERVER FOLLOWING TASKS HAPPEN:
1.Servlet-context object will be destroyed
2.Thread pool will be destroyed.
3.Container invokes the destroy() method for all servlets.
4.Container invokes the destroy() method for all filters.
5.All listeners will be destroyed.
6.All others running objects inside the container will be destyoyed and finally container is down and unable to process any user request.
reply
    Bookmark Topic Watch Topic
  • New Topic