background image

Tag Library Descriptors

<< Dynamic Attribute Example | Top-Level Tag Library Descriptor Elements >>
<< Dynamic Attribute Example | Top-Level Tag Library Descriptor Elements >>

Tag Library Descriptors

<%@ tag dynamic-attributes=
"colorMap"%>
<ul>
<c:forEach var=
"color" begin="0" items="${colorMap}">
<li>${color.key} =
<font color=
"${color.value}">${color.value}</font></li>
</c:forEach>
</ul>
Tag Library Descriptors
If you want to redistribute your tag files or implement your custom tags with tag handlers
written in Java, you must declare the tags in a tag library descriptor (TLD). A tag library
descriptor is an XML document that contains information about a library as a whole and about
each tag contained in the library. TLDs are used by a web container to validate the tags and by
JSP page development tools.
Tag library descriptor file names must have the extension .tld and must be packaged in the
/WEB-INF/
directory or subdirectory of the WAR file or in the /META-INF/ directory or
subdirectory of a tag library packaged in a JAR. If a tag is implemented as a tag file and is
packaged in /WEB-INF/tags/ or a subdirectory, a TLD will be generated automatically by the
web container, though you can provide one if you wish.
Most containers set the JSP version of this automatically generated TLD (called an implicit
TLD) to 2.0. Therefore, in order to take advantage of JSP 2.1 features, you must provide a TLD
that sets the JSP version to 2.1 if you don't have a TLD already. This TLD must be named
implicit.tld
and placed into the same directory as the tag files.
You set the JSP version using the version attribute of the root taglib element that of the TLD,
as shown here:
<taglib
xsi:schemaLocation=
"http://java.sun.com/xml/ns/javaee web-
jsptaglibrary_2_1.xsd
"
xmlns=
"http://java.sun.com/xml/ns/javaee"|
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
version=
"2.1">
Table 8­6
lists the subelements of the taglib element.
TABLE 8­6
taglib
Subelements
Element
Description
description
(optional) A string describing the use of the tag library.
Tag Library Descriptors
Chapter 8 · Custom Tags in JSP Pages
247