Friday, 2 December 2016

3 Difference between Web Server vs Application vs Servlet Containers in Java JEE

In the Java EE, or J2EE or JEE world, there are 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 same. The main difference between Web server and application server is that web server is meant to serve static pages e.g. HTML and CSS, while Application Server is responsible for generating dynamic content by executing server side code e.g. 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 application. 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 are a key feature of the application server in Java JEE world.

Web Server vs Application Server vs Web Containers

From the first part its 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 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.

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

3 Difference between Web Server vs Application vs Servlet Containers in Java JEE

That's all about the difference between Web Server, Application Server and Servlet Container in Java and JEE world. Remember, each one of the have different purpose and many times used together in 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 is also provided by Tomcat. On the other hand, if you have full fledged Java EE application including EJB then you need a proper application server like WebSphere, WebLogic or JBoss to host your application.

Related Posts