Back to Top

Saturday, 4 February 2012

J2EE: SERVLET: Servlet Life Cycle

  Life cycle of a servlet starts when its first load in the memory space in web server and ends when unloaded from the server memory. we can divide this in 3 steps.


  • Server loads the servlet class.
  • Creates an instance for the servlet class.
  • Server initializes the instance by calling init() method.

  • Server creates a request & a respond object based on the client's request.
  • Invokes the service() method of the servlet, passing the request respond object.
  • service() method process the request and use the respond object to create the client respond.
  • service() method can invoke can also invoke other methods like doGet(), doPost(), doDelete(), doOptions(), doPut() and doTrace().

  • Server calls the destroy() method to relinquish any resources such as file handles that are allocated to that servlet. destroy() method is invoked once in a servlet's life time.
  • Then the server unload the servlet and its objects, and it's memory can be garbage collected.

    Describes the Servlet Life Cycle within Web container or Web Server

                       *Unavailable exception thrown       *Initialization failed

    Anijit Sarkar

    14 Responses to “ J2EE: SERVLET: Servlet Life Cycle ”

    Jaydeep said...
    26 February 2012 at 13:26

    Its really helpful!!


    anij said...
    5 March 2012 at 02:00

    Thanks for visiting! :)


    namastu said...
    19 April 2012 at 01:13

    Thanks for sharing the information i found it very useful.

    Thanks again..


    anij said...
    19 April 2012 at 22:13

    @namastu

    you r most welcome my friend!!


    Asif said...
    6 September 2012 at 18:00

    its great yar !


    Asif said...
    6 September 2012 at 18:02

    have u any interest in data structures using c++


    Java Tutorials Blog said...
    22 December 2012 at 10:06

    very nice pictorial demonstration of servlet life-cycle. but remember that the destroy method won't be invoked if server crashes.


    tb said...
    11 September 2013 at 23:16

    ... when is the servlet loaded and unloaded? When the container (say Tomcat) gets started and shut down? ... or restarted?


    nasir husain said...
    11 September 2014 at 13:11

    important servlet interview questions with answer
    http://www.itsoftpoint.com/?page_id=2425


    nasir husain said...
    11 September 2014 at 13:14

    recently asked important servlet interview questions with answer
    http://www.itsoftpoint.com/?page_id=2425


    Michael Hussey said...
    19 August 2016 at 15:45



    Great Blog Thanks.

    Here You Can Find Your First Round Interview question For Job .

    Struts Interview Questions

    OOPs Interview Questions

    JSP Interview Questions


    Naviya Nair said...
    24 October 2016 at 15:13

    I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

    Online Java Training Java 8 Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai Java Training Institutes

    Java Training Institutes in Chennai Java Training in Chennai


    Naviya Nair said...
    24 October 2016 at 15:21

    I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

    Online Java Training Java 8 Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai Java Training Institutes

    Java Training Institutes in Chennai Java Training in Chennai


    Naviya Nair said...
    24 October 2016 at 15:29

    I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

    Online Java Training Java 8 Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai Java Training Institutes

    Java Training Institutes in Chennai Java Training in Chennai


    Post a Comment

    Popular Posts

    All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar
    blog links Web Directory Academics Blogs