Servlet的生命周期
代码部分:
package edu.xalead;
import javax.servlet.*;
import javax.servlet.Servlet;
import java.io.IOException;
public class ServletTest implements Servlet {
@Override/*出生之后(1次)*/
public void init(ServletConfig servletConfig) throws ServletException {
System.out.println("init 初始化代码!");
}
@Override/*配置对象*/
public ServletConfig getServletConfig() {
return null;
}
@Override/*每次处理请求时都会被调用*/
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
System.out.println("hello servlet!");
}
@Override
public String getServletInfo() {
return null;
}
@Override/*临死之前(1次)*/
public void destroy() {
System.out.println("执行销毁Servlet !");
}
}
代码结果展示: