The
examples
for this book are packaged as a standard Java web application, as
described in Chapter 2. This file structure is
supported by all Servlet 2.2-compliant servers, so you can use the
example application as a guide when you create your own web
applications. How a web application is installed is not defined by
the specification, however, so 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 need to
edit the application’s WEB-INF/web.xml
file using a text editor. Other servers may offer special deployment
tools that copy the files to where they belong and let you configure
the application using a special tool, such as web-based forms.
If you look in the ora
web application
directory, you’ll see that it contains an
index.htm
l file and a
number of directories corresponding to chapters in this book. 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, a classes
directory, and a
tlds
directory:
The
web.xml
file contains configuration information for the example application in the format defined by the Servlet 2.2 specification. It’s too early to look at the contents of this file now; we will return to parts of it when needed.The
lib
andclasses
directories are standard directories, also defined by the Servlet 2.2 specification. A 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, however, it’s easy to answer this question: if the classes are packaged in a JAR file, store the JAR file in thelib
directory; otherwise, use theclasses
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 five JAR files. Theorataglib_1_0.jar
file contains all the Java class files for the custom actions and beans used in this book. Thejdbc20_stdext_classes.jar
file contains classes that are part of the JDBC 2.0 Standard Extension and are used in the database examples. Thexalan.jar
,xerces.jar
, andxsl.jar
contain XML parser classes used for an example in Chapter 12.The
classes
directory contains the class for a servlet used to display the raw source code for the example JSP pages, so you can see what they look like before they are processed by the server. It also contains.properties
files containing localized text for the example in Chapter 11.The
tlds
directory is not defined by the Servlet 2.2 specification, but is the name used by convention for Tag Library Descriptor (TLD) files. Don’t worry about what this means now. As you read through this book, it will become clear.
If you want to try out some of your own JSP pages, beans, and custom
actions 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 if the classes are packaged in a JAR file or
not. If you want to use the book’s custom actions and beans in
another application, copy the files in both the
lib
and tlds
directories to
the web application structure for the other application.
Get Java Server Pages now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.