servlet Application Development Interface:
Javax.servlet.Servlet:
- Init () method: called after the method is constructed, before the service method;
- Service () Method: Call this method to allow the servlet to respond to the request, which cannot be invoked until the servlet is initialized successfully;
- Destroy () method: The servlet calls this method when a servlet is removed from the Service. This method does not invoke when all threads of this object service () method are not fully exited or are considered by the container to have a timeout operation.
- Getservletconfig () method: Get a servletconfig,
- Getservletinfo () Method: allows the servlet to provide information about the Host's servlet run
Servlet Life Cycle:
- The client sends the request
- servlet Container Parsing request
- Create a Servlet instance
- Calling the Init method
- Invoking the Service method
- Output response Information
- return response
- Calling the Destory method
The first time you visit a servlet:
The Servlet's constructor is invoked, and the call to Init () executes only once in the lifetime of a servlet
On the server Startup load Web site Is:
The service method is called
Exactly when the load needs to be set through the corresponding Servlet settings item <load-on-startup> node in the Web. XML configuration File:
1 load-on-thestartup flag container is instantiated at startup and invokes the priority of its init () method. 2 Its value indicates that the servlet should be loaded in order 3 is 0 or greater than 0 o'clock, indicating that the container loads and initializes the servlet when the app starts;4 If the value is less than 0 or unspecified, it means that only the first requested container is called in the servlet when the initializer calls the initialization function 5 The lower the value, the higher the servlet's priority, and the more loaded the app Starts. when the value of 6 is the same, the container is loaded in its own order of Choice.
Load-on-startup
When the servlet was destroyed:
The server shuts down; when the Web module is updated or stopped, the servlet container is based on the situation (destory METHOD)
Destory () method:
Called before the servlet instance is destroyed, only once in the life cycle of a servlet
The servlet life cycle can be divided into four phases ( summary ):
- Loading and Instantiating: invoking the constructor method, which is done by the servlet container
- Initialize: Call the Init method
- Handling Customer Requests: Service methods (doget, DoPost)
- Destroy: call destroy method before destroying
ServletConfig contains the parameters defined in the Web program deployment descriptor, ServletConfig is instantiated by the servlet container
After each web App launches, the servlet container creates a unique ServletContext object that contains information for the entire Web program
Servlets are multithreaded applications
Java EE Review Two