What is the difference between web and application server?

In this post, you will learn:

  • What is the difference between web and application server?
  • What is the directory structure of a java web application?
  • What is a deployment descriptor and why is it needed?

In order to execute a Java application, A web or application server having a servlet container is required. A web server knows only how to intercept HTTP requests and how to return contents of static web pages. It doesn’t know how to execute servlets. A servlet container extends the functionality of a web server by facilitating the execution of servlets in a sand-boxed (managed and secure) environment. Apache and IIS are web servers and Tomcat is a servlet container.

As servlet API need servlet container similarly other APIs of Java Enterprise Edition (JEE) need other runtime environments. e.g. JMS API need Messaging Server, EJB API need EJB container, JNDI API need Directory server etc. To facilitate the execution of applications which use one or more JEE APIs, a runtime environment called Application Server is introduced. An application server contains, web server, servlet container, EJB container, Messaging server, Directory server and many more features required by enterprise applications. Glassfish, Jboss, WebSphere are some well known application servers of Java.

For an analogy,  a web server can be thought of as a land-line classical phone which facilitate only voice calls, a web server with servlet container can be thought of as a simple mobile which facilitate messaging in addition to voice calls and an application server can be thought of as a smart phone which facilitate many more things. If you have a dynamic web application which doesn’t use any of the above mentioned JEE APIs then only a web server having a servlet container is sufficient for you.

As web applications can be deployed on different servers hence a standard directory structure and packaging format are required to make them server independent. Servlet specification defines the directory structure and packaging format for Java web applications. 

Directory structure of a java web application:

[one_half]

Notes:

1 – Folders marked with * are optional i.e some or all of them may not be required in each web application.

2 – Static resources can be HTML pages, CSS files, JS files, Images and other resources. Usually all these are stored in different folders.

3 – Lib folder is required only when the web application references third party libraries such as database drivers, frameworks etc.

4 – A JSP based web application doesn’t have servlet classes hence it doesn’t require classes folder.

5 – Each web application is deployed on the server as a self descriptive unit i.e. it contains the description of all its components in a standard format so that each server can manage them.

6 – Conventionally description of application components is provided in XML format through a file named web.xml.

7 – Web.xml file is called deployment descriptor. It is used by application programmers to provide the configuration information of application components to the server.

8 – In servlet 3 API, annotations are introduced to be used for providing configuration of application components to the server in place of web.xml.

[/one_half] [one_half_last] java_web_app_directory_structure [/one_half_last]

Structure of a simple web.xml:

A web application may have components other than servlets as you would come to know in the later posts. For a simple web application which has only servlets, web.xml file will have following elements:

<web-app>
  <servlet>
  <servlet-name>objName</servlet-name>
  <servlet-class>className</servlet-class>
  </servlet>
  <servlet-mapping>
  <servlet-name>objName</servlet-name>
  <url-pattern>servletURL</url-pattern>
  </servlet-mapping>
</web-app>
...

For each Servlet, a <servlet> & <servlet-mapping> element are required in web.xml. <servlet> element, tells the server by what name object of a servlet class is to be created. <servlet-mapping> element,  tells the server which servlet object is to be used for processing the request of which URL.


Its time to recap the main concepts:

  1. A web server knows how to intercept HTTP requests and how to send response. It doesn’t know how to execute servlets.
  2. Servlet container facilitate the execution of JRE within the server so that servlets can be executed.
  3. An enterprise application uses APIs such as EJB, JMS, JNDI etc.
  4. For the execution of enterprise applications, Application server is required.
  5. Components of web application are arranged in a standard directory structure so that they can be deployed on any web or application server.
If you like the post, then share it...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

4 thoughts on “What is the difference between web and application server?

  1. Sir,

    If am true , there is a typing mistake in paragraph 1,

    .. . ……EJB container, Messaging server, Directory server [[[[[[ any ]]]]]] many more features required by enterprise applications. Glassfish, Jboss, WebSphere are some well known application servers of Java. so so . . . .

    [[[[[[ any ]]]]]] on place of any it should be and
    Regards,
    karim

  2. Hello Sir, Can you recommend any book for android application development or learn J2EE covering all topic with frameworks. Please give response.

    1. Android, JEE and frameworks can’t be covered by a single book. You need to read separate books for all of them.
      For Android you can use: Programming Android
      For JEE: Java web programming (Servlet & JSP)
      For Struts: Struts 2: Design and programming
      For Spring: Pro Spring 3
      For Hibernate: Professional Hibernate

Leave a Reply

Your email address will not be published. Required fields are marked *