servlet的生命周期。
2016-03-29 16:24
211 查看
一个类extends HttpServlet。
public class TestServlet extends HttpServlet {
public TestServlet() {
super();
System.out.println("构造方法");
}
public void destroy() {
super.destroy();
System.out.println("destroy");
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("service()");
}
public void init() throws ServletException {
System.out.println("init");
}
}
启动tomcat,在url输入地址访问该servlet。
输出为:
构造方法
init
service()
之后再访问,不再调用构造方法和init()方法,直接输出 service()
关闭tomcat,调用destroy()方法。
public class TestServlet extends HttpServlet {
public TestServlet() {
super();
System.out.println("构造方法");
}
public void destroy() {
super.destroy();
System.out.println("destroy");
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("service()");
}
public void init() throws ServletException {
System.out.println("init");
}
}
启动tomcat,在url输入地址访问该servlet。
输出为:
构造方法
init
service()
之后再访问,不再调用构造方法和init()方法,直接输出 service()
关闭tomcat,调用destroy()方法。
相关文章推荐
- 学习Python os.popen启动程序
- 推荐一个免费的论文查重网站PaperFree:http://www.paperfree.cn
- 结对编程作业要求
- Oracle事务
- Java Thread.join()详解
- mysql 和 Linux 的密码修改
- Python 进阶 —— map-reduce
- redis-3.0.7 安装报错 error: jemalloc/jemalloc.h: No such file or directory解决方法
- 基于javascript实现简单的抽奖系统
- DHCP总结。
- 创建JFileChooser 对象时空指针异常(PS:求知篇)
- 解析CleanMyMac隐私保护内容与使用
- Git 的 .gitignore 配置
- codeforces 658C Bear and Forgotten Tree 3构造-多么痛的领悟
- 2016第七届蓝桥杯C/C++ B组省赛第四题
- iOS - 融云即时通讯的简单使用
- 11款最轻量级的CSS框架
- VC中CTreeContrl实现响应单击或双击事件
- HDU 5322 NTT与分治
- dijkstra算法