servlet 生命周期
![servlet life cycle](https://i-blog.csdnimg.cn/blog_migrate/ce3bb274777204c20ec4926f3d7e5572.png)
Loading Servlet Class : A Servlet class is loaded when first request for the servlet is received by the Web Container.
加载Servlet类:当Web容器收到对Servlet的首次请求时,将加载Servlet类。
Servlet instance creation :After the Servlet class is loaded, Web Container creates the instance of it. Servlet instance is created only once in the life cycle.
创建Servlet实例:加载Servlet类后,Web Container会创建它的实例。 Servlet实例在生命周期中仅创建一次。
Call to the init() method :
init()
method is called by the Web Container on servlet instance to initialize the servlet.调用init()方法: Web容器在servlet实例上调用
init()
方法以初始化servlet。Signature of init() method :
init()方法的签名:
public voidinit(ServletConfig config) throws ServletException
Call to the service() method : The containers call the
service()
method each time the request for servlet is received. The service() method will then call thedoGet()
ordoPost()
methos based ont eh type of the HTTP request, as explained in previous lessons.调用service()方法:每次收到servlet请求时,容器都会调用
service()
方法。 然后,service()方法将根据HTTP请求的类型调用doGet()
或doPost()
方法,如先前课程中所述。Signature of service() method :
service()方法的签名:
public voidservice(ServletRequest request, ServletResponse response) throws ServletException, IOException
Call to destroy() method: The Web Container call the
destroy()
method before removing servlet instance, giving it a chance for cleanup activity.调用destroy()方法: Web容器在删除servlet实例之前调用
destroy()
方法,从而使其有机会进行清理活动。
翻译自: https://www.studytonight.com/servlet/servlet-life-cycle.php
servlet 生命周期