SERVLET&JSP Learning notes: What is a Web container

Source: Internet
Author: User

What is a Web container

Web container (Container) is the only HTTP server recognized by servlet/jsp

    • At a specific level, the container is basically a program written in Java, running on the JVM, different types of containers will be responsible for different work, if the servlet/jsp Run Web container (Web Container), is also a Java write program. HTTP, the text of the communication protocol, how to become the Java object available in servlet/jsp, is actually the analysis and transformation of the container.
    • At an abstraction level, the Web container can be thought of as an HTTP server running servlet/jsp, so long as the written servlet/jsp conforms to the standard specification of the Web container, servlet/jsp can run on a variety of vendor-implemented web containers, regardless of the underlying real H What the TTP server is.

In Tomcat, for example, the role position of a container can be used to represent:

What is a Web container

Web container (Container) is the only HTTP server recognized by servlet/jsp

    • At a specific level, the container is basically a program written in Java, running on the JVM, different types of containers will be responsible for different work, if the servlet/jsp Run Web container (Web Container), is also a Java write program. HTTP, the text of the communication protocol, how to become the Java object available in servlet/jsp, is actually the analysis and transformation of the container.
    • At an abstraction level, the Web container can be thought of as an HTTP server running servlet/jsp, so long as the written servlet/jsp conforms to the standard specification of the Web container, servlet/jsp can run on a variety of vendor-implemented web containers, regardless of the underlying real H What the TTP server is.

In Tomcat, for example, the role position of a container can be used to represent:

Similar to the JVM between the Java program and the physical operating system, the Web container is between the entity HTTP Server and the Servlet, and just as writing a Java program must understand how the JVM interacts with the application, writing servlet/jsp must also know that the Web container such as How to interact with servlet/jsp, how to manage the servlet and other Facts (JSP is also translated, compiled, Loaded as a servlet, in the container of the world, really responsible for the request, response is the servlet).

A basic example of a request/response:

  • (1) The client (in most cases, the browser) makes an HTTP request to the WEB server.
  • (2) The HTTP server receives an HTTP request, transfers the request to the Web container, and the Web container analyzes the HTTP request content, creating various objects such as HttpServletRequest, HttpServletResponse, Httpservletsession, etc.).
  • (3) The WEB container has a requested URL that determines which servlet to use to process the request (developer-defined beforehand).
  • (4) The Servlet decides what to do with the information of the requesting object (Httpserveltrequest) and creates the response through the Response object (HttpServletResponse).
  • (5) The Web container communicates with the HTTP server, and the Web server translates the response into an HTTP response and passes it back to the client.

The Servlet is executed on top of the Web container, the Web container is started by the JVM on the server, and the JVM itself is an executable on the server, and when a request arrives, the Web container assigns one thread to each request (thread).

If multiple requests come in, only multiple threads are started for processing, instead of repeatedly booting the JVM multiple times. A thread is like a lightweight process in a process that can significantly reduce the performance burden by not having to start multiple processes repeatedly.

It is then important to note that the Web container may use the same Servlet instance to serve multiple requests. That is, multiple requests are equivalent to multiple threads accessing an object on the share, so you need to be aware of thread safety issues and avoid causing data confusion.

SERVLET&JSP Learning notes: What is a Web container

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.