Creating Tag Library Descriptor files in JSP
How to create a TLD file?
Explanation
Tag Library Descriptor or TLD files are used to define the tags for different objects or classes created in Java and that can be used in JSP.
Example :
<?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>sample</shortname>
<info>My sample tag</info>
<tag>
<name>hello</name>
<tagclass>mytag.Hello</tagclass>
<bodycontent>empty</bodycontent>
<info>
This is a simple hello tag.
</info>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>enc</name>
<tagclass>mytag.Encrypt</tagclass>
<bodycontent>empty</bodycontent>
<info>
This is a simple hello tag.
</info>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
From the above creating Tag Library Descriptor example, The "mytag.tld" file is a simple file with the version of XML, the encoding used and the document type is also specifed. First the taglibrary version is specified that is "1.0", the JSP version "1.1" is specified, the "<shortname>" tag specifies the prefix to be used to access the tld file. In the "info" tag any information can be given.
Inside the tag "tag" the "name", "tagclass" is specified, inside the "attribute" tag the name of the attributes passed can be specified, if required.