JSP and Beyond

a pragmatic primer on building web-based solutions with Java technologies

The Anatomy of a JSP Application

At first glance the directory structure for a JSP application can appear complex. Each JSP-based application that is deployed inside of an application server needs to follow a certain directory hierarchy.

Each section of the directory hierarchy has been created to serve a particular purpose as illustrated below. Once you become accustomed to the directory format, it becomes easily navigable and logically structured.

At the very root of the container’s file structure there is generally a directory to house the web applications. It is within this directory that you will place your application files. In the examples below, let us suppose that you have a web application name called “YourWebApp”.

Within this directory all static content should reside. This includes JSP, HTML and image files.

YourWebApp /WEB-INF/
The Web Application deployment descriptor (web.xml) lives within this directory. This deployment descriptor maintains all of your application settings that dictate how the container delivers your application. The following code sample shows a web.xml file that lets the container know that the default file for the directory is index.jsp and the application timeout is set at 30 minutes.

<?xml version=”1.0″ encoding=”UTF-8″?>

<web-app xmlns=”http://java.sun.com/xml/ns/j2ee”
xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”

This directory is private and not externally accessible by end users.

YourWebApp /WEB-INF/classes
Java classes and Servlets should reside in this directory. The directory is private and not externally accessible by end users, so they cannot request the source code for the files.

YourWebApp /WEB-INF/lib
This is where you can place a JAR fileand tag libraries. The directory is private and not externally accessible by end users. As above, this inherent safety mechanism stops end users from directly accessing this content.

A Quick Note on Development
During application development, it can be most advantageous to work with your application files in what is called an exploded format. The exploded format allows you to work directly with the directory structure, which makes it easier to work with. Once the application is ready for distribution, it can be packaged into a WAR file for easy portability by consolidating all of the above directories into a single file.