10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<br />

<br />

${color.key} =<br />

${color.value}<br />

<br />

<br />

Tag Library Descriptors<br />

If you want to redistribute your tag files or implement your custom tags with tag handlers<br />

written in <strong>Java</strong>, you must declare the tags in a tag library descriptor (TLD). A tag library<br />

descriptor is an XML document that contains information about a library as a whole and about<br />

each tag contained in the library. TLDs are used by a web container to validate the tags and by<br />

JSP page development tools.<br />

Tag library descriptor file names must have the extension .tld and must be packaged in the<br />

/WEB-INF/ directory or subdirectory of the WAR file or in the /META-INF/ directory or<br />

subdirectory of a tag library packaged in a JAR. If a tag is implemented as a tag file and is<br />

packaged in /WEB-INF/tags/ or a subdirectory, a TLD will be generated automatically by the<br />

web container, though you can provide one if you wish.<br />

Most containers set the JSP version of this automatically generated TLD (called an implicit<br />

TLD) to 2.0. <strong>The</strong>refore, in order to take advantage of JSP 2.1 features, you must provide a TLD<br />

that sets the JSP version to 2.1 if you don’t have a TLD already. This TLD must be named<br />

implicit.tld and placed into the same directory as the tag files.<br />

You set the JSP version using the version attribute of the root taglib element that of the TLD,<br />

as shown here:<br />

<br />

Table 8–6 lists the subelements of the taglib element.<br />

TABLE 8–6 taglib Subelements<br />

Element Description<br />

description (optional) A string describing the use of the tag library.<br />

Tag Library Descriptors<br />

Chapter 8 • CustomTags in JSP Pages 245

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!