Servlet's Life... - Coddicted

Servlet’s Life…

Initializing…
When the Web Container is started the container loads the servlet class and create the instance of  the servlet. The container calls the no-argument init() method (called only once) on the servlet instance after the servlet instance is created but before the servlet can service any request.
 
Servicing…

1. When a user clicks a link that has URL to a servlet, the request is send to the container.

2. The container sees the request is for a servlet, the container creates two objects:
        a. HttpServletResponse
        b. HttpServletRequest
 
3. The container finds the correct servlet based on the URL in the request, creates or allocates a thread for that request and calls the servlets service() method, passing the request and response  objects as arguments.
 
4. The service() method figures out which servlet method to call based on the HTTP method (POST,GET etc.) sent by the client and calls the corresponding servlet’s method passing the request and response objects as arguments.
 
5. The servlet uses the response object to write out the response to the client. The response goes back through the container.
 
6. The service() method completes so the thread either dies or returns to the container managed thread pool. The request and response object falls out of scope, so these objects are ready for  garbage collection.[The clients gets response]
 
Destroying…
Container calls the destroy() method(called only once) to give the servlet a chance to clean up before the servlet  is killed(i.e., made ready for garbage collection) 
 
source:HF Servlets and JSP

Back To Top
Rate this post

Leave a Reply