More Servlets and JavaServer Pages

Chapter 5: Controlling Web Application Behavior
with web.xml

To view source code for other chapters in this book, mouse over the table of contents bar on the left.

Source Code from Chapter

Note: right-click or shift-click on the links to download the associated file.

app-blank.zip.
Blank Web app to use as the starting point for your Web applications.
Uses servlet 2.4 (JSP 2.0) version of web.xml.

TestServlet.java. Simple servlet used to illustrate servlet naming
and custom URLs. Part of the deployDemo Web application.

web.xml.
Deployment descriptor for the deployDemo application.
See the first servlet element.

TestPage.jsp.
Simple JSP page that just prints
out the local part of the URL used to invoke it. Placed in the top level
of the deployDemo directory. Also see the associated servlet
and servlet-mapping entries in
web.xml.

SorryServlet.java. Simple servlet used to give error messages to
users who try to access default servlet URLs
(i.e., http://host/webAppPrefix/servlet/ServletName)
in Web applications that have disabled this
behavior.

InitServlet.java. Simple servlet used to illustrate servlet
initialization parameters. See the associated servlet element
in web.xml,
especially the init-param subelement.

InitPage.jsp.
A JSP page that contains a jspInit method and
is placed at the top level of the deployDemo Web page hierarchy.
Normally, a URL of http://localhost/deployDemo/InitPage.jsp
would invoke a version of the page that has no access to initialization
parameters and would thus show null for the
firstName and emailAddress
variables. However, the
web.xml
file assigns a registered name and then
associates that registered name with the URL pattern /InitPage.jsp.

ReportFilter.java. Simple filter that prints a report on the standard output
whenever the associated servlet or JSP page is accessed. See the
filter element of
web.xml.

NotFound.jsp.
A JSP page that could be returned to clients that provide
unknown filenames. See the error-page and
error-code elements of
web.xml.

DumbDeveloperException.java. Exception used to flag particularly onerous
programmer blunders. Used to illustrate the
exception-typeweb.xml element.
The class also contains a static method called
dangerousComputation that sometimes
generates this type of exception.

RiskyPage.jsp.
A JSP page that calls
dangerousComputation on random integer values.
See the error-page and
exception-type elements of
web.xml.

DDE.jsp.
JSP page that is displayed whenever a DumbDeveloperException
is thrown in the top level of a JSP page.

ContextReporter.java. Simple listener that prints a
report on the standard output
when the ServletContext is created or destroyed.
See the listener element of
web.xml.

deployDemo.war.
The entire deployDemo application in a single
Web ARchive (WAR) file.