Servlet生命周期

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Servlet生命周期相关的知识,希望对你有一定的参考价值。

 1 //servlet生命周期
 2 /* 
 3   init();初始化
 4   service();处理客户端请求
 5   destroy();终止(销毁)
 6 */
 7 
 8 //init()方法
 9 public void init() throws ServletException{
10     //初始化代码...
11 }
12 
13 
14 //service()方法
15 public void service(ServletRequest request,ServletResponse response) throws ServletException,IOException{
16 
17 }
18 /*
19   service() 方法由容器调用,service 方法在适当的时候调用 doGet、doPost、doPut、doDelete 等方法;
20   不用对service() 方法做任何动作,只需要根据来自客户端的请求类型来重写 doGet() 或 doPost() 即可.
21 */
22 
23     //doGet()方法
24     public void doGet(ServletRequest request,ServletResponse response) throws ServletException,IOException{
25         //servlet代码
26     }
27     //doPost()方法
28     public void doPost(ServletRequest request,ServletResponse response) throws ServletException,IOException{
29         //servlet代码
30     }
31 
32 
33 //destroy()方法
34 public void destroy(){
35     //终止化代码
36 }

技术分享

以上是关于Servlet生命周期的主要内容,如果未能解决你的问题,请参考以下文章

Servlet的生命周期

关于片段生命周期

servlet和filter的区别

调用 replace() 时片段的生命周期是啥?

Android片段生命周期:onResume调用了两次

在不存在的片段上调用片段生命周期和 onCreate 的问题