Chapter 22. Using Custom Tag Libraries
Introduction
A very powerful feature of JavaServer Pages technology is the ability to create your own XML tags for use in JSPs. Custom tags have been a part of the JSP specification since Version 1.1. JSP 2.0 is dedicated to making custom tag development less complex than prior versions. JSP 2.0’s introduction of simple tag handlers and tag files, which we cover in Recipe 22.8-Recipe 22.14, are a big part of this strategy.
Let’s familiarize ourselves with a few terms
before we move on to custom tag recipes.
A tag
is an instance of an XML element and a
member of a specified namespace.
For example, the prefix for all tags
associated with this cookbook is
cbck
. The JSP
refers to an individual tag associated
with the cbck
namespace (say, the
myTag
tag) as
follows:
<cbck:myTag>whatever this tag does...</cbck:myTag>
Tags are XML elements; therefore, their names and attributes are case sensitive. A collection of tags that provide similar functionality or that logically collaborate with each other is called a tag library . Developers can install one or more tag libraries in a web application.
A Java class called the tag handler provides the tag’s functionality in a JSP. A custom action is a tag that you invent for use in JSPs and that is powered behind the scenes by a tag-handler object that the web container keeps in memory.
A classic tag handler uses the tag extension API that evolved from JSP v1.1 to 1.2. A simple tag handler is a Java class ...
Get Java Servlet & JSP Cookbook 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.