Web Server VS Application Server VS Web Containers

Typically, a Web server refers to an execution infrastructure that handles HTTP requests and responses; a servlet container refers to a component that handles the lifecycle for servlets; an application server refers to a framework (servlet container, EJB container, JSP engine, MQ container, etc.) for handling Web applications. However, a Web container has a couple of meanings depending on the source. Most refer to a Web container as the part of an application server that manages servlets, JavaServer Pages (JSP) files, and other Web-tier components. Some refer to a Web container as the infrastructure for managing the lifecycle for Web services.

1) Examples

In order to better understand the difference, you must know some popular examples of the web server, application server, and web containers. Apache and IIS are two popular web servers. Apache is used everywhere including Java world but IIS is more popular in Microsoft ASP .NET world. From Java EE perspective couple of popular application servers are IBM WebSphere, Oracle WebLogic, Glassfish and Redhat's JBoss. Coming back to web containers or servlet engines, Apache Tomcat and Jetty are two of the most popular Servlet engine in Java web world.

2) Features and Responsibility

The significant difference between web server and application server comes from a responsibility perspective. Web servers are responsible for serving static content e.g. HTML over HTTP protocol while application server is responsible for serving dynamic content, managing EJB pool, facilitating distributed transaction, facilitating application lookup over JNDI, application security and others. While web containers are only responsible for generating HTML by executing JSP and Servlet on Server side.

3) Service

One more difference between an application server and web server comes from the service perspective. It's expected from a Web server to provide HTTP protocol level service while application server is supposed to provide more powerful and dynamic Web service and business level service via EJB (Enterprise Java Beans). Essential services like Database connection pooling is not only provided by application server but also by Web containers like Tomcat. You can read more about how to setup connection pool in tomcat here.

4) Usage

Once you know the difference between web and application server and web containers, it's easy to figure out when to use them. You need a web server like Apache HTTPD if you are serving static web pages. If you have a Java application with just JSP and Servlet to generate dynamic content then you need web containers like Tomcat or Jetty. While, if you have Java EE application using EJB, distributed transaction, messaging and other fancy features than you need a full fledged application server like JBoss, WebSphere or Oracle's WebLogic.

Last updated