Creating a Tag Library Descriptor

When the web container converts custom action elements into code that creates and calls the correct tag handler, it needs information about which tag handler implements which custom action element. It gets this information from the Tag Library Descriptor (TLD).

The TLD is an XML file that contains information about all the custom actions in one library. A JSP page that uses custom actions must identify the corresponding TLD and the namespace prefix used for the actions in the page with the taglib directive, described in more detail in the next section:

<%@ taglib uri="/WEB-INF/tlds/orataglib_1_0.tld" 
  prefix="ora" %>
...
<ora:redirect page="main.jsp" />

The JSP page then uses the TLD to find the information it needs when it encounters a custom action element with a matching prefix.

Here’s an example of part of a TLD:

<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> <taglib> <tlibversion>1.0</tlibversion> <jspversion>1.1</jspversion> <shortname>ora</shortname> <uri> /orataglib </uri> <info> A tab library for the examples in the O'Reilly JSP book </info> <tag> <name>redirect</name> <tagclass>com.ora.jsp.tags.generic.RedirectTag </tagclass> <bodycontent>JSP</bodycontent> <info> Encodes the url attribute and possible param tags in the body and sets redirect headers. </info> <attribute> <name>page</name> <required>true</required> ...

Get JavaServer Pages Pocket Reference 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.