The web container keeps up the life cycle of a servlet occurrence. Let's examine the life cycle of the servlet:
As displayed in the above given diagram,the three states of a servlet are: new, ready and end. If the Servlet instance is made because of this the servlet is in a new state. After supplicating the init() method, Servlet comes within the ready state. Servlet performs all the tasks within the ready state. When the web container supplicates the destroy() way, it shifts to the last state.
The classloader manages to load the servlet class. When the primary request for the servlet is acquired by the web container then the servlet class is loaded.
The web container makes the graphic of a servlet once after loading the servlet class. In the life Cycle of servlet servlet instances are made only once.
The web container calls the init method just one occasion after creating the servlet instance. The init method is employed to initialize the servlet. It's the life cycle of the javax.servlet.Servlet interface. Below is the syntax method of the init.
public void init(ServletConfig config) throws ServletException
The web container calls the service way whenever a request for the servlet is acquired. If the servlet isn't started, it follows the primary three steps as explained above then calls the service method. If the servlet is started already, it calls the service method. Notice that servlet is initialized on just one occasion. Below is the syntax of the service method of the Servlet Interface:
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
The Web Container calls the destroy method once before disconnecting the servlet instance from the service. It gives the servlet a chance to clear up the resources for example memory, thread etc. Below is the syntax of the destroy method of the servlet interface.
public void destroy()