O'Reilly logo

Java Examples in a Nutshell, 3rd Edition by David Flanagan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Packaging a Web Application

Now that we've considered each of the pieces that constitute our ListManager web application, we'll look at how those pieces are put together into a web application WAR file. For completeness, we'll include all the servlets and JSP pages from this chapter, not just the ones that implement the mailing list manager. In order to do this, we must:

  1. Write a web.xml file that configures all the servlets

  2. Arrange that configuration file—along with the servlet implementation classes, JSP pages, and related files—in their correct places in a directory hierarchy

  3. Zip them all up (with the jar tool) to create a WAR file

Recall from the start of this chapter that we used these commands to compile the servlet classes and create the WAR file:

javac -d WEB-INF/classes/ *.java
jar cMf je3.war \
        index.html *.jsp *.jspx ListManager/*.jsp \
        WEB-INF/web.xml WEB-INF/tags/*.tag WEB-INF/classes

We'll consider the directory hierarchy of the web application first, and then look at the web.xml file.

Web Application Directory Structure

Our je3 web application is structured as follows:

/

This is the root directory for the application. The servlet container will map a file x in this directory to a URL like this:

http://localhost:8080/je3/x
                        
/index.html

The default file served for the URL "je3/". This is just a plain HTML file that contains links to the various examples contained in the web application.

/*.jsp

The hello.jsp, hello2.jsp and hello3.jspx examples go here.

/ListManager/

A directory for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required