The life cycle of the "Javaweb notes" servlet

Source: Internet
Author: User

1. Loading and instance

A servlet cannot run independently, it must be deployed into a servlet container, instantiated by a container, and invoking the servlet's method. When the servlet container is started or when a client sends a request, the servlet container looks in memory for the servlet instance and, if it does not exist, creates a servlet instance. If an instance of the servlet exists, the instance request is fetched directly from memory.

Note: The servlet container loads the Servlet class based on the location of the Servlet class, and after the load succeeds, the servlet instance is created by the container

2. Initialization

After the instantiation is complete, the servlet container will invoke the servlet's init () method for initialization, which is intended to allow the Servlet object to do some work before processing the client request. For example: Set the connection parameters and establish a JDBC connection.

Note: For each servlet instance, the Init () method can only be called once.

3. Service

Once the Servlet is initialized, it is in a ready state to respond to the request. When the servlet container receives a client request, the service () method of the servlet is called to process the request client request. The servlet instance obtains the client's request through the ServletRequest object and sets the response information by invoking the method of the Servletresponse object.

4. Destruction

When a servlet container determines whether a servlet should be released (shutting down a container or needing to reclaim resources), the container invokes the servlet's Destroy () method, which indicates that those resources can be reclaimed by the system rather than directly.

Note: The Destroy () method is executed when the server is stopped, or when the system recycles resources.

The life cycle of the "Javaweb notes" servlet

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.