Taglib Directive
Defines a tag library and prefix for the custom tags used in the JSP page.
JSP Syntax
<%@ taglib{uri="URI" | tagdir="/WEB-INF/tags[/subdir]+"} prefix="tagPrefix" %>
XML Syntax
None. Included in <jsp:root> and in any other XML element using the xmlns attribute instead:
<anyxmlelement xmlns:prefix="{uri | urn:jsptld:path |
urn:jsptagdir:/WEB-INF/tags[/subdir]+}" >
Examples
<%@ taglib uri="http://www.jspcentral.com/tags" prefix="public" %> <public:loop> ... </public:loop>
Description
The taglib directive declares that the JSP page uses custom tags, names the tag library that defines them, and specifies their tag prefix.
You must use a taglib directive before you use the custom tag in a JSP page. You can use more than one taglib directive in a JSP page, but the prefix defined in each must be unique.
Tutorials on creating custom tags are available at http://java.sun.com/products/jsp/taglibraries.html#tutorials.
Attributes
uri="URI"- The Uniform Resource Identifier (URI) that uniquely locates the TLD that describes the set of custom tags associated with the named tag prefix. A URI can be any of the following:
- A Uniform Resource Locator (URL), as defined in RFC 2396, available at
http://www.hut.fi/u/jkorpela/rfc/2396/full.html - A Uniform Resource Name (URN), as defined in RFC 2396
- An absolute or relative pathname
- If the URI is a URL or URN, then the TLD is located by consulting the mapping indicated in
web.xmlextended using the implicit maps in the packaged tag libraries. If URI is pathname, it is interpreted relative to the root of the web application and should resolve to a TLD file directly, or to a JAR file that has a TLD file at location META-INF/taglib.tld.
- The Uniform Resource Identifier (URI) that uniquely locates the TLD that describes the set of custom tags associated with the named tag prefix. A URI can be any of the following:
tagdir="/WEB-INF/tags[/subdir]+"- Indicates this prefix is to be used to identify tag extensions installed in the
/WEB-INF/tags/directory or a subdirectory. An implicit tag library descriptor is used. A translation error must occur under any of these conditions:
- The value does not start with
/WEB-INF/tags/. - The value does not point to a directory that exists.
- If this attribute is used in conjunction with the
uriattribute.
- Indicates this prefix is to be used to identify tag extensions installed in the
prefix="tagPrefix"
See Also
- <jsp:root>
- Section JSP.8.4 of the JSP 2.0 Specification for information on the implicit tag library descriptor.
