Chapter 5: Controlling Web Application Behavior
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.
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.
Deployment descriptor for the deployDemo application.
See the first servlet element.
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
SorryServlet.java. Simple servlet used to give error messages to
users who try to access default servlet URLs
in Web applications that have disabled this
InitServlet.java. Simple servlet used to illustrate servlet
initialization parameters. See the associated servlet element
especially the init-param subelement.
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
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
A JSP page that could be returned to clients that provide
unknown filenames. See the error-page and
error-code elements of
DumbDeveloperException.java. Exception used to flag particularly onerous
programmer blunders. Used to illustrate the
The class also contains a static method called
dangerousComputation that sometimes
generates this type of exception.
A JSP page that calls
dangerousComputation on random integer values.
See the error-page and
exception-type elements of
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
The entire deployDemo application in a single
Web ARchive (WAR) file.