The difference between a container, an application server, and a Web server

Source: Internet
Author: User

What is a container

The servlet does not have a main () method. They are controlled by another Java application, a Java application called a container (Container)
Tomcat is a container in which the Web server application (Apache) Gets a pointer to the servlet request, instead of handing the request to the servlet itself, but to the container where the servlet is deployed. The method by which the servlet will be called by the container to provide HTTP requests and responses to the servlet.

Customer-to-Request--->web server app--->web container app--->servlet-------->web server Host

Customer <--Response <---Web server app <---web container app <---servlet<--------Web server Host

Containers provide:

Communication support: Establish ServerSocket, listen to a port, create a stream, etc.

Life cycle Management: Control servlet life and death, responsible for loading classes, instantiating and initializing Servlets, invoking servlet methods, and enabling servlet instances to be garbage collected;

Thread support: The container automatically creates a new Java thread for each servlet request that is received, and ends when the response HTTP service method thread finishes running.

Life-style security: You can use the XML deployment profile to configure (or modify) security without hard-coded writing to the Servlet class code.

JSP support.

Container handling servlet

Customer---->HTTP Request----> Container----->servlet

Container---> Create request (HttpServletRequest)/Response (HttpServletResponse) object

Container---> Request---> Response---> Thread (the container finds the correct servlet based on the URL, creates or assigns a thread for the request, and passes the request and response object to the servlet thread)

The container-----The >servlet Service () method service calls the Doget () or Dopost () method based on the type.

Doget () generates a dynamic page and "plugs" the page into a reference to the response object.

At the end of the thread, the container turns the Response object into an HTTP response, sends it back to the client, and then deletes the request and response object.

Differences between the application server and the Web server

First, we should have a clear concept of the application server and the Web server. The so-called application server is the server that provides the application, there are many applications, such as Java applications, Ruby applications, or C # applications.


So what is a Web server? is to provide a Web-enabled server, mainly HTTP services, including the download of images, and so on a series of web-related.


Well, you ask, why can't we just use the application server? The application server also provides HTTP services, such as Tomcat.
Then we start from the reality. When you browse a Web page, what happens when you feel slow? We only consider the page itself. Of course, the more pictures you have, the slower they appear.
Well, at least we realize that some static resources, examples, can seriously affect the speed of page opening. Of course, this is only one aspect.


So what's the use of Web servers? One of the advantages of a Web server is the processing of static information. For example some static HTML, pictures, and so on other static things

Understanding of Tomcat Server and Apache

The Tomcat server is a free open source Web application server. Because of its advanced technology, stable performance and free, it has been favored by Java enthusiasts and has been recognized by some software developers, becoming a popular Web application server.

One, Tomcat and application server

So far, Tomcat has been considered the executor of the Servlet/jsp API, as well as the so-called servlet container. However, Tomcat does not only do this, it also provides the implementation mechanism for JNDI and JMX APIs. However, Tomcat is still not an application server because it does not provide support for most of the Java EE APIs.

Interestingly, many application servers today often use Tomcat as a container for their servlet and JSP APIs. Because Tomcat allows developers to embed tomcat into their applications simply by adding a line of acknowledgements. Unfortunately, many commercial application servers do not comply with this rule.

For developers, choosing Tomcat is a great solution if you're looking to build Java Web applications using servlet, JSP, Jndi, and JMX Technologies, but to find support for other EE APIs, Finding an application server or using Tomcat as an application server is a good solution, and the third Way is to find a separate Java EE API implementation and then combine them with Tomcat. Although consolidation can bring about problems, this approach is most effective.

Ii. Tomcat vs. Web server
Tomcat is a container that provides support for Servlets and JSPs to run. Servlets and JSPs can generate dynamic Web content based on real-time needs. For Web servers, Apache only supports static web pages, and it is powerless to support dynamic Web pages, while Tomcat can serve dynamic Web pages and support static Web pages. Although it is not as fast as the usual Web server, it is not as rich as the Web server, but Tomcat is gradually expanding to support static content. Most Web servers are written in the underlying language, such as C, and take advantage of the features of the corresponding platform, so Tomcat execution speed written in plain Java is unlikely to be comparable to them.

In general, the large site is a combination of Tomcat and Apache, Apache is responsible for accepting all HTTP requests from the client, and then forwarding Servlets and JSP requests to Tomcat for processing. After Tomcat finishes processing, the response is passed back to Apache, and the final Apache returns the response to the client.

I feel the Apache server parsing the static Web page of the professional server

We have a built-in server in Tomcat to access apache! But the speed is still not working.

The difference between a container, an application server, and a Web server

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.