servlet生命周期
package com.bjsxt.servlet.life;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//servlet是单利模式
//servlet模式是懒汉式:加载类的时候没创建对象
//饿汉:加载类时就加载对象
//可以通过配置来修改servlet让其变成饿汉时。
/**
* Servlet implementation class ServeltLife
*/
/*1:加载
2:初始化调用init()
3:调用service()--调用doget()或者dopos
4.调用destory()销毁
*/
/*@WebServlet("/ServeltLife")*/
public class ServeltLife extends HttpServlet {
public ServeltLife(){
System.out.println("ServeltLife.ServeltLife()");
}
@Override
public void init() throws ServletException {
System.out.println("ServeltLife.init()");
}
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("ServeltLife.service()");
super.service(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("ServeltLife.doGet()");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("ServeltLife.doPost()");
}
@Override
public void destroy() {
System.out.println("ServeltLife.destroy()");
}
}