The invocation process of the servlet-life cycle _ Inheritance Structure

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.