j2ee: The Tag Library Descriptor [15/27] ![]() ![]() ![]() |
In order for your tag library to be processed properly by the Servlet container, you must supply a configuration file known as a tag library descriptor. This basically servers the purpose of web.xml for a web application, it is information that the container uses to manage the libraries at runtime
http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd for JSP 2.0
http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd for JSP 1.2
http://java.sun.com/dtd/web-jsptaglibrary_1_1.dtd for JSP 1.1>
TLD structure:
taglib - requires tlib-version, jsp-version,
short-name, and tags. Optional are uri, description, validator
(a TagLibraryValidator), and listeners.
tag - requires name and tag class, optional
are body-content (JSP/empty, or tagdependent),
variables entries (scripting variable names),
attributes, tei (TagExtraInfo) classes, and description
attribute - requires name,
required (whether it is required, false by default),
rtexprvalue (whether it is a runtime JSP expression),
type (must be fully qualified)
Examples:
<?xml version="1.0" encoding="UTF-8" ?>
<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">
<tlib-version>2.0</tlib-version>
<jsp-version>2.0</jsp-version>
<short-name>se452</short-name>
<uri>/se452</uri>
<display-name>se452-taglib</display-name>
<small-icon></small-icon>
<large-icon></large-icon>
<description>
A set of example tag libraries for SE452 at DePaul University
</description>
<tag>
<name>date</name>
<tag-class>se452.tags.DateTag</tag-class>
<body-content>empty</body-content>
<description>
Prints the current time and date
</description>
</tag>
<tag>
<name>debug</name>
<tag-class>se452.tags.DebugTag</tag-class>
<body-content>JSP</body-content>
<description>
Includes the contents of the tag if debug request parameter
is set to true
</description>
</tag>
<tag>
<name>select</name>
<tag-class>se452.tags.SelectTag</tag-class>
<body-content>empty</body-content>
<description>
Displays an html select with preselected options
</description>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>selected</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>list</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
</taglib>