Java EE Review Two

Source: Internet
Author: User

servlet Application Development Interface:

Javax.servlet.Servlet:

    • Init () method: called after the method is constructed, before the service method;
    • Service () Method: Call this method to allow the servlet to respond to the request, which cannot be invoked until the servlet is initialized successfully;
    • Destroy () method: The servlet calls this method when a servlet is removed from the Service. This method does not invoke when all threads of this object service () method are not fully exited or are considered by the container to have a timeout operation.
    • Getservletconfig () method: Get a servletconfig,
    • Getservletinfo () Method: allows the servlet to provide information about the Host's servlet run

Servlet Life Cycle:

    1. The client sends the request
    2. servlet Container Parsing request
    3. Create a Servlet instance
    4. Calling the Init method
    5. Invoking the Service method
    6. Output response Information
    7. return response
    8. Calling the Destory method

The first time you visit a servlet:

The Servlet's constructor is invoked, and the call to Init () executes only once in the lifetime of a servlet

On the server Startup load Web site Is:

The service method is called

Exactly when the load needs to be set through the corresponding Servlet settings item <load-on-startup> node in the Web. XML configuration File:

1 load-on-thestartup flag container is instantiated at startup and invokes the priority of its init () method.  2 Its value indicates that the servlet should be loaded in order 3 is 0 or greater than 0 o'clock, indicating that the container loads and initializes the servlet when the app starts;4  If the value is less than 0 or unspecified, it means that only the first requested container is called in the servlet when the initializer calls the initialization function 5 The lower the value, the higher the servlet's priority, and the more loaded the app Starts. when the value of 6 is the same, the container is loaded in its own order of Choice.
Load-on-startup

When the servlet was destroyed:

The server shuts down; when the Web module is updated or stopped, the servlet container is based on the situation (destory METHOD)

Destory () method:

Called before the servlet instance is destroyed, only once in the life cycle of a servlet

The servlet life cycle can be divided into four phases ( summary ):

    1. Loading and Instantiating: invoking the constructor method, which is done by the servlet container
    2. Initialize: Call the Init method
    3. Handling Customer Requests: Service methods (doget, DoPost)
    4. Destroy: call destroy method before destroying

ServletConfig contains the parameters defined in the Web program deployment descriptor, ServletConfig is instantiated by the servlet container

After each web App launches, the servlet container creates a unique ServletContext object that contains information for the entire Web program

Servlets are multithreaded applications

Java EE Review Two

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.