Getting Started with servlet development (4) Servlet lifecycle

Source: Internet
Author: User

servlet development standards, the servlet has its own small framework, a standard servlet program to have a complete lifecycle, what is the lifecycle? Let's take a look at the standard servlet development.

Servlet life cycle

Lifecycle is the cycle of a program's existence, and the servlet is managed by the container, so the container determines the lifecycle.

A servlet program is a Java program running on the server side whose lifecycle is controlled by a Web container that includes loading, initializing, servicing, destroying, uninstalling five parts

The lifecycle is as shown in the figure above, and it is a cycle of a program.

1. Load servlet

The Web container is responsible for loading the servlet, the container is Tomcat, and the container is responsible for creating the servlet instance when the Web container is started or when the servlet is used for the first time. However, the user must specify the location of the servlet (the package in which the servlet resides) through the deployment descriptor (Web.xml), and after the successful loading, the Web container instantiates the servlet in a reflective manner.

2. Initialize

When a servlet is instantiated, the container invokes the Init () method to initialize the object so that the Servlet object completes some initialization before processing the client request, and if the initialization fails, the servlet is downloaded directly

3. Processing services

When a request is submitted, the servlet invokes the Service () method (commonly used doget () and Dopost ()) for processing. In the service () method, the servlet can either accept the customer's request through ServletRequest or set the response information using Servletresponse

4. Destruction

When the Web container is closed or a servlet is detected to be removed from the container, the Destroy () method is automatically called to allow the instance to release the resource that it occupies

Related Article

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.