您的位置:首页 > 其它

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()方法。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: