Java EE Learning (2)--What is container "Liang Gregor Learning notes moved"

Source: Internet
Author: User
Tags glassfish

What is a container for a Java program, the JVM (Java Virtual Machine) is its operating system,. Java is the. class file,. Class for the JVM, it is its removable file, and your Java program basically recognizes only one operating system, the JVM.

When you start writing a servlet/jsp program, you have to start the concept of a touch container (Container), which is also used on Collection such as list, set, which is the cluster (Collection) object that holds and holds the object, , for writing servlet/jsp, the concept of a container is more general, and in its most basic function, it does not only hold objects, but also the life cycle of the objects and the connection of the related services.

On the surface, the container says, it is actually a Java-written program that runs on the JVM, and different types of containers will be responsible for different jobs, and if the Web container (Web Container) that servlet/jsp is running is a Java program, think about it, The HTTP text-like message is how to become a Java object (such as HttpServletRequest, HttpServletResponse, etc.) that is available in the servlet/jsp you write, which is actually a container for you to dissect and transform.

At the abstraction layer, you can think of the Web container as the servlet/jsp server you write, yes! Just as the Java program recognizes the JVM as the operating system, the SERVLET/JSP program is on the abstract surface, and only the Web container is a Web server, as long as you write the servlet/jsp is in line with the standard of the Web container, your servlet/ JSPs can be run on a web container of different vendors, without having to base a true Web server.

Of course, there's actually a Web server, so back to the real world, the Web container is a Java-written application that can be part of a physical Web server program, managing the lifetime of a Servlet object, providing Web services based on HTTP requests and responses.

In the case of Tomcat, the role position of the container can be represented by the following image:


Just as the JVM is between the Java program and the physical system, the Web container is between the actual Web server and the servlet, and as you write the Java program must understand how JVM/JRE and your application interact, and you write servlet/ The JSP also has to know how the container will interact with your servlet/jsp, how to manage the servlet, and so on (JSP is translated, translated, and Loaded as a servlet, in the world of containers, the real responsibility is to request and respond to servlets).

A basic example of a request/response is:
    1. The client (in most cases, the browser) has an HTTP request for the Web server.
    2. Web server receives HTTP request, will request to be handled by Web container, Web container will parse HTTP request content, build various objects (like HttpServletRequest, HttpServletResponse, httpsession, etc.).
    3. The Web container is determined by the URL of the request to use which servlet is used for the request (in advance by the developers to define).
    4. The servlet's request for an object (HttpServletRequest) depends on how it is handled, through the Response object (HttpServletResponse) to establish the response.
    5. The Web container communicates with the Web server, and the Web server transforms the response into an HTTP response and returns it to the client.

Not only is writing servet/jsp need to understand the Web container, in the Java EE domain regardless of which technology, is related to the container interest, write servlet/jsp need to understand the Web container, write EJB need to understand the EJB container, write application client needs to understand the application client container, Even if you are writing an applet, there will be an applet container's features to understand.

The following image is a container for Java EE 6 APIs files from Java EE 6 Tutorial:


For the Java EE 6 specification, servlet 3.0/jsp 2.2, you can use the actual container can be Tomcat 7, or Glassfish V3,tomcat 7 focus on the part of the Web container, Glassfish v3 is a complete application server, It also includes the functionality of the Web container (and, of course, other vendors as well). See the original: http://openhome.cc/Gossip/ServletJSP/

Java EE Learning (2)--What is container "Liang Gregor Learning notes moved"

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.