We know that Servlet Container manages the life cycle of Servlet, there are four phases of servlet life cycle.
- Servlet Class Loading – When container receives request for a servlet, it first loads the class into memory and calls it’s default no-args constructor.
- Servlet Class Initialization – Once the servlet class is loaded, container initializes the ServletContext object for the servlet and then invoke it’s init method by passing servlet config object. This is the place where a servlet class transforms from normal class to servlet.
- Request Handling – Once servlet is initialized, its ready to handle the client requests. For every client request, servlet container spawns a new thread and invokes the service() method by passing the request and response object reference.
- Removal from Service – When container stops or we stop the application, servlet container destroys the servlet class by invoking it’s destroy() method.
No comments:
Post a Comment