The life cycle of the servlet

Source: Internet
Author: User

First, the servlet life cycle

1. Web Container loading servlet class

2. Initialize the Servlet object (constructor run)

3. The servlet calls the Init () method (the servlet is called only once in a lifetime and is completed before the container invokes the service () method)

4. Call the service method (process customer request doget (), DoPost () method, each request is run in a separate thread)

5, call Destroy (), the container calls this method, so that the servlet is garbage collected before the opportunity to reclaim resources and the Init () method, can only be called once.

Ii. The servlet architecture

The servlet interface, init (), service (), and Destory () methods are life cycle methods.

Genericservlet is an abstract class that implements the Servlet interface and implements most of the basic servlet methods

Public abstract class Genericservlet implements Servlet, servletconfig,java.io.serializable

HttpServlet is also an abstract class inheritance Genericservlet, which implements a service method to handle HTTP requests and responses.

Public abstract class HttpServlet extends Genericservlet

Finally write a servlet of your own to inherit the HttpServlet.

Iii. Requests and responses

Public interface HttpServletRequest extends ServletRequest

Public interface HttpServletResponse extends Servletresponse

These are implemented by containers to implement the HttpServletRequest method that is related to HTTP, such as Cookie,head and session sessions, as well as responses.

The life cycle of the 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.