The life cycle of the servlet
The servlet is a class file that inherits the HttpServlet servlet is a server applet that provides a unified programming interface for Servlets servlet typically runs common servlet container tomcat in a container, Jetty/resin
Servlet life process: Refers to the entire process from creation to invocation of a Servlet object in server memory, to destruction
1:classloader---Loading
2:new---Instantiation: When a client requests through a URL, the Web container automatically calls the Servlet's construction method according to the XML configuration, instantiating the object
3:init ()---Initialization: Call the Init () method from the Servlet object, read the configuration information of the servlet in Web. XML, and provide the relevant data for the service method
4:service---Processing requests call the service () method through the object, and if it is inherited HttpServlet, the corresponding doget ()/dopost () is invoked according to the request method in the request header information
5:destory ()---Exit service: is not called immediately after the service () method call, but is determined by the JVM. The Destroy () method of the instance is called when the JVM needs to destroy some objects and free up memory space
To run the servlet, you must also configure a Web. xml file registration mechanism to find the class file that needs to be run
@WebServlet ("/servletlife")//----If you add annotations without Web. xml
So how do you master a servlet?
First 1. Create a servlet to inherit from HttpServlet
Overriding the Doget/dopost method in the Web. XML configuration
Servlet life cycle
The concept of cookie/session/application
Request Forwarding
Servlet Cookie
Servlet Mastering Cookie Illustration