First, the servlet life cycle
1. Web Container loading servlet class
2. Initialize the Servlet object (constructor run)
3. The servlet calls the Init () method (the servlet is called only once in a lifetime and is completed before the container invokes the service () method)
4. Call the service method (process customer request doget (), DoPost () method, each request is run in a separate thread)
5, call Destroy (), the container calls this method, so that the servlet is garbage collected before the opportunity to reclaim resources and the Init () method, can only be called once.
Ii. The servlet architecture
The servlet interface, init (), service (), and Destory () methods are life cycle methods.
Genericservlet is an abstract class that implements the Servlet interface and implements most of the basic servlet methods
Public abstract class Genericservlet implements Servlet, servletconfig,java.io.serializable
HttpServlet is also an abstract class inheritance Genericservlet, which implements a service method to handle HTTP requests and responses.
Public abstract class HttpServlet extends Genericservlet
Finally write a servlet of your own to inherit the HttpServlet.
Iii. Requests and responses
Public interface HttpServletRequest extends ServletRequest
Public interface HttpServletResponse extends Servletresponse
These are implemented by containers to implement the HttpServletRequest method that is related to HTTP, such as Cookie,head and session sessions, as well as responses.
The life cycle of the servlet