Step4: Servlet life cycle

serLife

1-Servlet Class loading –

The class Classloader is responsible to load servlet class.It loads, when the first request for the servlet is made.

2-instantiation of class (objet creation by server) –

The servlet object is created once in the entire servlet life cycle.

3-init () – 

It is called only once in the entire lifecycle.

4-service() – 

Service() method is called every time when a request for a servlet is received.
This method is used to handle requests for the servlet.

The service() method accepts 2 parameters: a request object and a response object.
It overrides doGet() and doPost() method.

Note- (i) doGet() method — doGet() method is used to handle the get request.

(ii) doPost() method — doPost() method is used to handle the Post request.

5-destroy() – 

This method is called only once in the entire life cycle of a servlet.