FAQ: Can the uri attribute for a JSP's taglib point to a remote Tag Library Description (TLD) file?


Can the uri attribute for a JSP's taglib point to a remote Tag Library Description (TLD) file?


In brief, the answer is 'no'. The uri attribute can:

1) point to a location on disk (relative to the web application root directory) or
2) map to a location on disk via the web application's web.xml file.

In the web.xml file, the taglib element contains two subelements: taglib-uri and taglib-location. These define a unique string used by the JSP's taglib uri parameter (taglib-uri) and the path to the TLD on disk, relative to the web application (taglib-location). Here is a portion of the J2EE JSP deployment descriptor defining these elements:

<xsd:complexType name="taglibType">
- <xsd:annotation>
<xsd:documentation>The taglibType defines the syntax for declaring in the deployment descriptor
that a tag library is available to the application. This can be done to override implicit map
entries from TLD files and from the container.</xsd:documentation>
- <xsd:sequence>
- <xsd:element name="taglib-uri" type="j2ee:string">
- <xsd:annotation>
<xsd:documentation>A taglib-uri element describes a URI identifying a tag library used in the web
application. The body of the taglib-uri element may be either an absolute URI specification, or a
relative URI. There should be no entries in web.xml with the same taglib-uri
- <xsd:element name="taglib-location" type="j2ee:pathType">
- <xsd:annotation>
<xsd:documentation>the taglib-location element contains the location (as a resource relative to
the root of the web application) where to find the Tag Library Description file for the tag
<xsd:attribute name="id" type="xsd:ID" />

All xsds for J2EE defined deployment descriptors can be found at the following url:
J2EE Specifications

Here is an example:

In a JSP file, the following taglib is specified:

<%@ taglib uri="http://www.esri.com/argcis/webcontrols" prefix="ags" %>

The uri appears to reference a remote resource, however the web application's web.xml file shows how the uri is mapped to a local file:


In this case, the uri is mapped to the arcgis_webcontrols.tld in the web application's WEB-INF directory.

It is also possible reference a TLD without configuring the deployment descriptor (web.xml). The web container (for example, Tomcat) will read TLD files present in a JAR file's META-INF directory (in the web applications WEB-INF\lib directory). The TLD will contain a reference to the uri used to map the taglib to the TLD: