测试servlet生命周期
package bysj01;
import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
@WebServlet("/servlet01")
public class servlet01 implements Servlet {
@Override
public void destroy() {
// TODO Auto-generated method stub
System.out.println("释放了Servlet对象...");
}
@Override
public ServletConfig getServletConfig() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getServletInfo() {
// TODO Auto-generated method stub
return null;
}
@Override
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
System.out.println("对Servlet完成初始化操作");
}
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("执行了Servlet的业务方法...");
}
}
控制台就会出现运行的整个测试过程
注:只有service是在一个生命周期中多次调用,init、destory和无参构造函数都只会调用一次