A servlet's life cycle has three phases. These are depicted in the following diagram:
Let's look at each phase of the servlet life cycle:
- Initialization: The first phase in the Servlet's life cycle is initialization. In this phase, the resources that a servlet needs to serve the request are created and initialized. The Servlet classes implement the contract of the javax.servlet.Servlet interface, and the javax.servlet.Servlet interface declares the init() method that represents the initialization. When the servlet is loaded by the container, it invokes the init() method to create and initialize ...