Introduction to Servlet containers

Source: Internet
Author: User

Servlet is a general extension of servers that support Java. Its most common purpose is to expand Web servers and provide very secure, portable, and easy-to-use CGI alternatives. It is a dynamic loading module that provides services for requests from Web servers. It runs completely on the Java Virtual Machine. Because it runs on the server side, it does not depend on the browser compatibility.

Servlet container:

Handles customer requests, sends requests to Servlet, and returns results to the customer. The actual implementation of containers of different programs may change, but the interfaces between containers and servlets are defined by Servlet APIs, this interface defines the Servlet container's method to be called on the Servlet and the object class passed to the Servlet.

Servlet lifecycle:

1. Create an instance of Servlet in the Servlet container

2. The Container calls the init () method of the instance.

3. If the container has a request for this Servlet, call the service () method of this instance.

4. The Container calls its destroy () method before destroying the instance.

5. Destroy and mark the instance for garbage collection

Once a Servlet is requested, there is no way to prevent the container from executing a complete lifecycle.
The container creates an instance of the Servlet when it is called for the first time, and keeps the instance in the memory for processing all the requests. The container can decide to remove the instance from the memory at any time. In a typical model, the container creates a separate instance for each Servlet, and the container does not create a new thread every time it receives a request, instead, a thread pool is used to dynamically allocate threads to incoming requests. However, from the Servlet's point of view, the effect is the same for creating a new thread for each request.

  1. New Servlet and JSP features
  2. Talking about Servlet Web Server
  3. Implement Servlet applications in Weblogic
  4. Communication between Servlet and CGI
  5. Use MIDlet to activate 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.