Previous Section  < Day Day Up >  Next Section

3.5 Example Web Application Overview

The examples for this book are packaged as a standard Java web application. All servers compliant with the JSP 2.0 specification support this file structure, so you can use the example application as a guideline when you create your own web applications. How a web application is installed isn't defined by the specification, though, and it varies between servers. With Tomcat, you simply copy the file structure to the special webapps directory and restart the server. To modify the configuration information for an application, you must edit the application's WEB-INF/web.xml file using a text editor. Other servers may offer special deployment tools that copy the files where they belong, and let you configure the application using a special tool or through web-based forms.

If you look in the jsfbook web application directory, you'll see that it contains an index.html file and a number of directories. These directories contain all the example JSP and HTML pages.

There's also a WEB-INF directory with a web.xml file, a lib directory, and a classes directory. We will look at this in much more detail later, starting in Chapter 4, but here's a quick review:

web.xml file

The web.xml file contains configuration information for the example application in the format defined by the servlet and JSP specifications. It's too early to look at the contents of this file now; we will return to parts of it when needed.

Lib and classes directories

The lib and classes directories are standard directories, also defined by the servlet specification. A very common question asked by people new to servlets and JSP (prior to the standard web application format) was, "Where do I store my class files so that the server can find them?" The answer, unfortunately, differed depending on which implementation was used. With the standard web application format, it's easy to answer this question: if the classes are packaged in a JAR file, store the JAR file in the lib directory; otherwise, use the classes directory (with subdirectories mirroring the classes' package structure). The server will always look for Java class files in these two directories.

The lib directory for the example application contains a number of JAR files. The custom_jsf_lib_1_x.jar and sample_app_1_x.jar files contain all the Java class files for the book examples. The other JAR files contain the JSF and JSTL Reference Implementation, plus all the classes that these implementations depend on.

The classes directory contains the class for the JSPSourceServlet that displays the raw source code for the example JSP pages, so you can see what they look like before the server processes them. It also contains all .properties files with localized text for the example in Chapter 11 and a few test servlets described in Chapter 4.

If you want to try out some of your own JSP pages, beans, and other classes while reading this book, simply add the files to the example application structure: JSP pages in any directory except under WEB-INF, and Java class files in either the classes or the lib directory—depending on whether the classes are packaged in a JAR file or not. Alternatively, you can, of course, create your own web application structure and copy the JAR files you need from the example application.

    Previous Section  < Day Day Up >  Next Section