Creating the Tag Library Descriptor

Now you have a good idea about what the code for a tag handler looks like. But when the JSP 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). As you will see in the next section, the JSP container also uses the TLD information to verify that the attribute list for an action element is correct.

The TLD is an XML file with information about all 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 (this is described in more detail later).

<%@ 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 an action element with a matching prefix.

Example 16.8 shows a part of the TLD for the custom actions in this book.

Example 16-8. Tag Library Descriptor (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 ...

Get Java Server Pages 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.