当前位置:网站首页>Lifecycle of Servlet

Lifecycle of Servlet

2022-06-22 09:13:00 C_ x_ three hundred and thirty

Servlet The life cycle of can be expressed in three ways :

  1. init(): Only once , Responsible for loading Servlet Initializes Servlet object
  2. service() : The core approach , commonly HttpServlet There will be get,post Two ways to deal with it . Calling doGet and doPost Method is constructed servletRequest and servletResponse Request and response objects as parameters .
  3. destory(): Stop and uninstall Servlet When the , Responsible for releasing resources

Initialization phase :Servlet start-up , Will read the information in the configuration file , Constructs the specified Servlet object , establish ServletConfig object , take ServletConfig Called as an argument init() Method .

 

 init() Further explanation of

1.   load Servlet Class and .class Corresponding data

2.  establish ServletConfig object

3.  establish Servlet object

Every time a request comes to the container , Will produce HttpServletRequest And HttpServlceResponse object , And in the call service() Method is passed in as a parameter .

stay WEB After the container starts , Will read Servlet Set up information , take Servlet Class loads and instantiates , And for each Servlet Setting information generates a ServletConfig object , And then call Servlet Interface init() Method , And will produce ServletConfig Object is passed in as a parameter .

原网站

版权声明
本文为[C_ x_ three hundred and thirty]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220910014693.html