3 Difference between Web Server vs Application Server vs Servlet Containers - Apache vs JBoss vs Tomcat

In the Java EE, or J2EE or JEE world, there is a lot of confusion between terminology, which is quite evident that now we have three words (J2EE, Java EE, and JEE) to describe the same technology platform. You will see Java developers using the terms like Web Server, Application Server, and Web containers interchangeably but they are not exactly the same. The main difference between a Web server and an application server is that a web server is meant to serve static pages like HTML and CSS, while an Application Server is responsible for generating dynamic content by executing server-side code like JSP, Servlet, or EJB.

One of the most popular web servers is Apache HTTPD which is often used in conjunction with Tomcat to host many Java web applications. 

Now, Tomcat is not exactly an application server, it's more of a servlet engine or web container or also known as servlet containers because it provides the runtime environment for Servlet and JSP but doesn't provide the services like EJB and distributed transaction which is a key feature of the application server in Java JEE world.



Web Server vs Application Server vs Web Containers

From the first part it is clear that Web server serves static content, but, both web containers and application servers dynamic content. Let's see a couple of more points to understand the difference between Web and Application Server as well Servlet engines like Tomcat and Jetty.



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 the Microsoft ASP .NET world. 

From Java EE's 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 the Java web world.



2. Features and Responsibility

The significant difference between the 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 the 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 the server side.

This is also one of the popular questions on Java JEE interviews, but for better preparation, you can also refer Java Programming Interview Exposed book, one of the best to prepare for Java web development interviews.



3. Service

One more difference between an application server and a web server comes from the service perspective. It's expected from a Web server to provide HTTP protocol level service while the 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 set up a connection pool in tomcat here.


4. Usage

Once you know the difference between web and application servers 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 a Java EE application using EJB, distributed transaction, messaging, and other fancy features then you need a full-fledged application server like JBoss, WebSphere, or Oracle's WebLogic.

You can also use the web server and application server together in the same setup as shown in the following example:

Difference between Web Server vs Application vs Servlet Containers



That's all about the difference between Web Server, Application Server, and Servlet Container in Java and JEE world. Remember, each one of them has a different purpose and many times used together in the Java Web world. 

For example, one of the popular setups is apache fronting Tomcat. You can use this setup if your Web application is only using JSP and Servlet and doesn't need EJB or distributed transaction feature. 

More basic services like Database connection pooling are also provided by Tomcat. On the other hand, if you have a full-fledged Java EE application including EJB then you need a proper application server like WebSphere, WebLogic, or JBoss to host your application.


8 comments:

  1. As you mentioned ,"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."

    But as far as i know,
    you can configure
    -database pool using - tomcat pooling or dbcp
    - security - default or spring security
    - jndi lookup is supported by tomcat using resource-ref

    So, I am not able to understand full difference between container and application server.

    ReplyDelete
    Replies
    1. Hello Swapnil,
      You are right Tomcat provides database connection pooling but it doesn't provide an EJB container to run EJB, that's the main difference between a servlet container like Tomcat and a JEE aplication server like Glassfish or WebSphere.

      Delete
  2. but what if we are using Springs only , no EJBs then , do we need a application server?

    ReplyDelete
    Replies
    1. You can use Tomcat also if you are using Spring for web application.

      Delete
  3. No. Spring is used for developing applications and for deploying it, we can use either web/appn server whichever is suitable.
    I prefer using apache tomcat in most of the cases.

    ReplyDelete
  4. Thanks for the great article. However, it is still not clear to me what is the difference between an app server and a web container. it seems like they are the same, only app server serves EJB.

    ReplyDelete
  5. True apart from serving EJB I don't understand why we need Application Server

    ReplyDelete
  6. From this article what i understood is :

    Web Server - Serving Static Content like HTML,CSS. e.g. Apache & IIS
    Application Server - Serving dynamic content like JavaEE application e.g. IBM Websphere, JBOSS
    Servlet Container - To serve simple dynamic content like JSP/Servlet e.g. Tomcat,Jetty

    ReplyDelete

Feel free to comment, ask questions if you have any doubt.