|
Source Code Archive
More Servlets and JavaServer Pages
Chapter 11: New Tag Library Features in JSP 1.2
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.
-
SessionCountTag.java. Tag that prints out the number of active sessions.
-
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.xml taglib
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.
-
index.jsp. Home page. Uses the custom tags.
-
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.
-
NestingValidator.java. A validator that verifies that tags follow
proper nesting order.
-
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.
-
nesting-test1.jsp. Page with proper tag nesting order.
-
nesting-test2.jsp. Another page with proper tag nesting order.
-
nesting-test3.jsp. A page with improper tag nesting order.
-
nesting-test4.jsp. Another page with improper tag nesting order.
-
CatchTag.java. Tag that traces the life cycle of tags that
implement the
TryCatchFinally interface.
-
catch-tag-taglib.tld. TLD file for tag library that
uses a simple tag to illustrate
the behavior of the
TryCatchFinally interface.
-
catchTest.jsp. Page that uses
CatchTag. Requires the
styles.css
style sheet and the
Utils class.
-
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.
-
repeat-test1.jsp. JSP page that uses
-
RepeatTag1.
-
RepeatTag2.java. Tag that repeats the body the specified
number of times. JSP 1.2 version.
-
repeat-test2.jsp. JSP page that uses
-
RepeatTag2.
- taglibs.war.
The entire
taglibs application bundled in
a WAR (Web ARchive) file.
URLs Referenced in Chapter
More Information
-
J2EE training courses from the author. Available on-site at your
company or at public venues.
- Free online version of
Core Servlets & JavaServer Pages.
Complete text of book in PDF.
-
Home page for Core Servlets and JavaServer Pages 2nd Edition (Vol 1).
Includes the table of contents, index, sample chapters, source code archive, etc.
-
Home Page for More Servlets and JavaServer Pages.
Includes the table of contents, index, source code archive, etc.
-
Free online version of More Servlets and JavaServer Pages.
- Servlet and JSP Programming Resources.
Download sites, servers, IDEs, tutorials, books, job listings, and more.
-
Tutorials and lecture notes on servlets, JSP, Struts, JSF, and Java 5.
PDF version free for all. PowerPoint version free for qualified university instructors.
- Servlet and JSP
programming resources. Specs, documentation, servers, IDEs,
hosting providers, books, training, etc.
- Java Programming Resources.
General resources on Java technology. Compilers, editors, IDEs, tutorials, books,
user forums, and more.
|