Friday, 3 February 2012
Do you like this Article?
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.