Servlet Life Cycle

Servlet Life Cycle


Posted in : Servlet Posted on : October 30, 2010 at 6:13 PM Comments : [ 0 ]

In this tutorial you will learn about the servlet life cycle and there method

Servlet Life Cycle

The life cycle of the servlet is controlled by the servlet container. The servlet container is responsible for doing following task

  1. When the first request is made for servlet the containet loads the servlet class and initiates it.
  2. Then make an instance of servlet class.
  3. Initializes the servlet class by calling init() method.
  4. Call the service method passes the request response object to the service method.
  5. If container need to remove the servlet then call the destroy() method to finalize the servlet.

Servlet Life Cycle

Basically there are three methods in servlet lyfe cycle which servlet calls

  1. init()- This method is called to initialize  a servlet. In servlet 2.4 specification if you do not call init() method in your servlet program then the container call it implicitly.
  2. service()- This method is called to execute the business logic written in servlet. This is the method which you must have to override, when you are writing a servlet.
  3. destroy()- This method is called to finalize the servlet.

Note- The servlet call init() and destroy() method only once called during its life cycle.

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics