the life cycle of the servletExecution process: constructor-"Init Method-" Loop "service method"-"Destroy Method" (normal off Tomcat) * 1. The constructor executes first (creating the Servlet:init,service,destroy method), all of which are non-static methods. You must use an object to make a call * 2. A servlet class has only one object in the life cycle * The 3.service method executes on each request * The 4.destroy method executes normally only when Tomcat shuts down normally and does not execute if no access is closed * Do not write wrap-up work in the Destroy method * The 5.servlet class must be decorated with public, and the servlet constructor must be publicly parameterless * (the following programs are written in order of execution)Examples of programs:public class Servlet_life extends HttpServlet {public servlet_life () {System.out.println ("constructor"); } public void Init () throws Servletexception {System.out.println ("Run init ()"); } protected void Service (HttpServletRequest arg0, HttpServletResponse arg1) throws Servletexception, Ioexcep tion {System.out.println ("service: Hello"); } public void Destroy () {System.out.println ("in Progress Destroy ()"); }
2016.8.23 the first small pen (Java Web servlet life cycle)