Servlets are container managed. The life and death of servlets is under the control of the Servlet Engine. Servlet engine is developed strictly according to the Servelt specification. Our servlet also is written aonforming the same specification and by following the Servlet API. Therefore the servlet container can manage the servlet life cycle. The servlet life cycle steps describe the process by which the servlet container loads, instantiates, unloads and invokes its life cycle methods.
Life Cycle:
- The servlet container loads the servlet class that we developed and deployed into it. This can happen either at the time of web application startup or on receiving the client request for the first time.
- The servlet engine creates the servlet instances.
- Servlet engine creates the ServletConfig object.
- Servlet engines create the init method by suppyling ServletConfig object as argument.
- Servlet engine creates ServletRequest object & ServletResponse objects.
- Servlet engine calls the public service method and supplies the above two objects as arguments.
- Within the public service method these two objects are converted into Http specific objects and public service method calls protected service method.
- Within the protected service method client request type is calibrated (GET or POST). Depending upon the type of request, protected service method calls either doGet() or doPost(). In one of these methods a servlet developers implements the clinet request processing clode that involves.
i) Evaluating the HttpServletRequest object and capture the user input.
ii) Producing dynamic data by communicating with the database.
iii) Building dynamic web content and sending it to the client using HttpServletResponse object. - If the container receives another client request, process starts from strp 5.
- When the container is instructed to keep the servlet out of service, the servlet engine calls the destroy method on the servlet instance just before the servlet instance is garbage collected.
1 comments:
When a client request is made, the service method is called and passed a request and response object. The servlet first determines whether the request is a GET or POST operation. It then calls one of the following methods: doGet or doPost. The doGet method is called if the request is GET, and doPost is called if the request is POST. Both doGet and doPost take request (HttpServletRequest) and response (HttpServletResponse).
Post a Comment
Type here your comments