The life cycle of the Java----servlet

Source: Internet
Author: User

The servlet life cycle is divided into three phases:

1, Initialize phase call init () method

2, call the service () method in response to the customer request phase

3, Terminate phase call Destroy () method

Servlet initialization phase:

The servlet container loads the servlet at the following times:

The 1,servlet container starts automatically when certain servlets are loaded to implement it only on the web. Add the following code between <Servlet></Servlet> in the XML file:

<loadon-startup>1</loadon-startup>

2, after the servlet container is started, the customer first sends a request to the servlet

After the 3,servlet class file is updated, remount the servlet

After the servlet is loaded, the servlet container creates a servlet instance and invokes the servlet's init () method for initialization. The init () method is called only once throughout the servlet's life cycle.

Servlet response phase: When a servlet receives and responds to a customer request, the client first sends a request.

Service () is defined in the Javax.servlet.Servlet interface, which is implemented in Javax.servlet.GenericServlet. And Doget/dopost is realized in the Javax.servlet.http.HttpServlet, Javax.servlet.http.HttpServlet is Javax.servlet.GenericServlet Sub-class. All this is understood, in fact all requests are processed first by service (), and in the Javax.servlet.http.HttpServlet Service () method, the main thing to do is to determine whether the request type is Get or Post, and then call The corresponding Doget/dopost is executed.

The life cycle of the Java----servlet

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.