首先来看Servlet的相关接口
javax.servlet.Servlet
1 /** 2 * A servlet is a small Java program that runs within a Web server. 3 * Servlets receive and respond to requests from Web clients, 4 * usually across HTTP, the HyperText Transfer Protocol. 5 **/ 6 //javax.servlet.Servlet接口 7 public interface Servlet { 8 //servlet容器会保证servlet实例化后开始服务前调用init方法 9 public void init(ServletConfig config) throws ServletException; 10 11 public ServletConfig getServletConfig(); 12 13 public void service(ServletRequest req, ServletResponse res) 14 throws ServletException, IOException; 15 16 public String getServletInfo(); 17 //servlet容器关闭时被调用,tomcat的shutdown.bat 18 public void destroy(); 19 }