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.
Updates: Updated tag file examples can be found
here (basics) and
here (advanced).
These examples have been updated to JSP 2.0, so
the code is substantially different than in the rest of the
More Servlets & JSP
source code archive.
The
updated examples are bundled as
MyEclipse projects,
but can easily be used in regular Eclipse or without an IDE.
ActiveSessionCounter.java. Listener that keeps track of the number of sessions
that the Web application is currently using.
SessionCountWarningTag.java. If the number of active sessions is above the limit,
this tag prints a warning. Otherwise, it does nothing.
session-count-taglib-0.9-beta.tld.
A tag library that lets you print out the number of
sessions currently in memory and/or a warning about
the session count exceeding the limit.
The tlib-version number and the TLD filename are intended
to suggest that this tag library is in development. In
such a situation, you want to use the
web.xmltaglib
element to define an alias for the TLD filename. You
would want to do so even if you weren't trying
to accommodate Tomcat 4.0, which only reads listener
declarations from TLD files that are declared that way.
web.xml. Deployment descriptor for Web application of this chapter.
test.jsp,
make-sessions.html, and
ColorUtils.java. Page and associated utilities that merely load multiple
copies of the same JSP page. When used in a browser that has cookies disabled,
it forces server to create 49 new sessions for each request.
SAXValidator.java. A "validator" that really just prints out an outline
of the JSP page (in its XML representation). The
validate method always returns null, so the page is
always considered valid.
PrintHandler.java. A SAX handler that prints out the start tags, end tags,
and first word of tag body. Indents two spaces
for each nesting level.
OuterTag.java. Custom tag that prints out a simple message.
A TagLibraryValidator will
enforce a nesting order for tags associated with this class.
InnerTag.java. Custom tag that prints out a simple message.
A TagLibraryValidator will
enforce a nesting order for tags associated with this class.
NestingHandler.java. A SAX handler that returns an exception if either of
the following two situations occurs:
The designated outer tag is directly or indirectly
nested within the outer tag (i.e., itself).
The designated inner tag is not directly
or indirectly nested within the outer tag.
nested-tag-taglib.tld. TLD file for tag library that has two tags:
outerTag and innerTag.
A TagLibraryValidator will enforce the following
nesting rules:
innerTag can only appear inside outerTag. It can
be nested, however.
outerTag cannot be nested within other outerTag
instances.
Utils.java. Class with a static method that sometimes throws
an exception.
RepeatTag1.java. Tag that repeats the body the specified
number of times. JSP 1.1 version.
repeat-taglib.tld. TLD file for tag library that has two tags:
repeatTag1 and repeatTag2.
These are JSP 1.1 and JSP 1.2 versions of simple looping tags.