O'Reilly logo

Java Servlet & JSP Cookbook by Bruce W. Perry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

22.9. Creating a TLD for a Simple Tag Handler

Problem

You want to create a TLD for a simple tag handler.

Solution

Use the JSP 2.0-style TLD for the simple tag handler.

Discussion

The simple tag handler derives from the JSP 2.0 API, so you can use the TLD version from JSP 2.0 as well. Example 22-7 shows the taglib start tag and the various xmlns attributes that your TLD must reproduce exactly. Then, unless you are using JSP 2.0 TLD features such as the tag-file element, you can specify the tag element and its nested elements with the same XML syntax that you used for the prior TLD version.

Example 22-7. A JSP 2.0 TLD file for a simple tag handler

<taglib xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=
     "http://java.sun.com/xml/ns/j2ee 
     http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0"
>

<!-- THE REST OF THE XML CONTENT IS THE SAME AS THE JSP 1.2 TLD VERSION EXCEPT FOR <jsp-
version>2.0</jsp-version> -->
    
    <tlib-version>1.0</tlib-version>
    <jsp-version>2.0</jsp-version>
    <short-name>cbck</short-name>
    <uri>com.jspservletcookbook.tags</uri>
    <description>Cookbook custom tags</description>
    
    <tag> <name>simplelogo</name> <tag-class>com.jspservletcookbook.SimpleLogoTag</tag-class> <body-content>JSP</body-content> <description>This tag writes a logo inside the JSP.</description> <attribute> <name>heading</name> <required>true</required> <rtexprvalue>true</rtexprvalue> <description> The heading level for the logo; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required