A Web application is a collection of many different types of files, a typical web application might include
among others
• Servlets
• HTML Pages
• Image, audio, video
• Java Server Pages (JSP Pages)
• A deployment descriptor and other configuration file.
The concept of web application was introduced in version 2.2 of the Java Servlet specification.
A web application is organized with a structured hierarchy of directories, with particular type of files stored in
particular directories.
These directories can then be packaged into a web application archive (WAR) file.
Directory Structure
The directory structure of a web application has two parts:
1. A directory WEB-INF that contains the resources that is not to be directly downloaded to a client. This
Directory is private the client does have direct access to the files in this directory.
The WEB-INF directory typically contains dynamic resources such as servlets, as well as configuration
2. A directory that contains those resources that are intended to be publicly available. This includes all the
subdirectories of this directory, except of course for the private WEB-INF directory.
This Directory typically contains static resources such as HTML and image files.

web application structure

– is the root directory of the web application.
Public resources – files in my MyWebApp (or subdirectories)
                               file in images folder (or subdirectories)
                               file in literature folder(or subdirectories)
Private resources – files contains within the WEB-INF directory. Resources that are
                                 Only accessible to the container.
A public resource is any file that is accessible to the client of the web application. Typical public resources
• HTML, XML and JSP documents.
• Image, audio and video files.
• Java applets – classes as well as jar files containing applets.
• Microsoft office documents: world, Excel, etc.
Client browsers can download these resources unchanged and render them as required.
For example, when an HTML page includes an <APPLET> tag that refers to an applet in a jar file.
The web container delivers the JAR file to the client browser unchanged.
Typically, the container reads the static resources from the file system, and writes the contents directly to the
network connection. The interpretation of the contents of these resources is the responsibility of the client
browser. In order to help the browser render the file correctly, the container sends the MIME type of the file.
These MIME types can be set in the deployment descriptor of the web application.
Note: Although JSP pages are included as public resources in a web application; the container does not show
them directly to clients. The Container automatically converts JSP Page into Servlets.The Servlets is then
compiled and invoked to generate the response for the client.
However, since a JSP Page is often considered more to an HTML document than to a java class, JSP Pages are
also included under public resources.

Private Resources

Of course, there are certain resources that clients should not load directly. There may be files that the client
should not view, such as configuration files or they may be files that the container must perform some
processing on before sending the response to the client, like servlets. These private resources are stored in the
WEB-INF directory, or its subdirectories.
The Types of resources that clients should not download directly include:
• Servlets – These components include application logic, and possibly access to other resources such as
database. Any other file in the web application that servlets access directly.
• Resources that are meant for execution or use on the server side, such as java class file and JAR files
for classes used by your servlets.
• Temporary files created by your applications.
• Deployment descriptors and other configuration files.
These resources are private and as such are accessible only to their own web application and the container. In
order to accommodate private resources the web container requires the WEB-INF directory to be present in
your application. It your web application does not contain this directory it will not work.
The WEB-INF directories includes:
• A web.xml file. This is the deployment descriptor.
• A Subdirectory named classes. This directory is used to store server-side Java class files such as
servlets and other helper classes, structured according to the usual Java packaging rules.
• A lib subdirectory to contain JAR files used by the web application.

Advantage of the Structure

• Each application exists in a ‘sand-box’. The public and private resources of an application are
independent of any other application that the container may be running.
• When a new application is added to the J2EE server, we can simply add the appropriate context root
in the deploy tool of the reference implementation, without disturbing any other application.
• The Container knows where to look for classes. This means that you do not need to explicitly add
these classes and JAR files to the CLASSPATH.
• The difference between a conventional web server and a web container is that each web application
has its own document root.
• Similar to the public resources, Private resources of different web applications are stored in different
• According to the Servlet specification a container should load classes/JAR files of each web
application using a different class loader. it is for this reason that servlets, JSP Pages, and other
classes that are part of one web application cannot see classes in other application and therefore
cannot share static variables or singleton classes, for Example. This is easily achieved by the
structure discussed above.
Thus, even if you deployed the same web application twice (each mapping to a different URL) as for as
container is concerned they are two entirely different applications. such applications cannot share information.
As a result, web containers create a virtual partitioning of web applications within the container.