Servlet Invocation procedure
The browser enters the Web site,dns resolves the domain name into the server's IP address, the browser takes a request line, and many request headers to find the server.
1. Analyze which virtual host is requested, view the host request header, and access the default virtual host without the host request header
2. Analyze which Web resource in the current virtual host is being accessed, and analyze the resources of which web app is currently accessed from the request line
3. Find the Web. XML to see if there is a corresponding virtual path
The life cycle of the Servlet
1. When the servlet is first accessed, the server creates a servlet object.
2. immediately after the object is created, call the init () method do the initialization operation.
3. the created object will always reside in memory, serving for subsequent requests .
4. every access request to this servlet will cause the servlet to Service () method of the implementation.
5.for each access request, theServlet engine creates a new httpservletrequest Request object and a a new httpservletresponse Response object, and then passes the two objects as arguments to the the Service () method of the Servlet , and theservice method calls the Doxxx method separately according to the request .
6. before the servlet is destroyed, the server invokes the servlet 's Destroy () method do some aftercare work.
7. theServlet is destroyed when the Web app is removed from the container, or when the server is shut down .
The inheritance structure of the Servlet
Servlet Interface -- defines the Basic methods that the Servlet should have
|--genericservlet-- General basic servlet implement for infrequently used methods in this implementation class into the The basic implementation of the for service design for abstract method
|--httpservlet- based on the common Servlet , Further enhancements are made to the HTTP protocol : Real now the Service method in Genericservlet to determine the current request mode . , call the corresponding to the doxxx method so that we only need to inherit from the process of developing the Servlet HttpServlet, covering the specific doxxx method to be processed can be based on the different requester different types of processing are implemented . in general, do not overwrite the parent class Service method just overwrite Doget/dopost can do it.
The invocation process of the servlet-life cycle _ Inheritance Structure