Custom Tag Library Declarations

Custom tag libraries are declared and associated with a prefix through namespace declarations in a JSP Document. In Example 17-10, you see that the JSTL core tag library is declared with an xmlns prefixed attribute in the <c:forEach> element. As in XML, you can declare all namespaces you need either in the root element or in nested elements (where it applies only to that element and its children). The custom tag library prefix is the part of the attribute name following xmlns:, and the attribute value is usually the URI for the library (as defined either in the web.xml file or in the TLD file for the library). That’s how the JSTL core library is declared in Example 17-10. If you want to use the TLD or JAR file path instead of a URI value, you must use a value starting with urn:jsptld: followed by the path, for instance:

<html xmlns:ora="urn:jsptld:/WEB-INF/lib/orataglib_3_0.jar" 
  ...>

If the custom tag library consists of a set of tag files directly in the web application structure (i.e., a library that you would identify with the tagdir attribute of a taglib directive in a regular JSP page), the value must start with urn:jsptagdir:, followed by the path to the directory:

<html xmlns:my="urn:jsptagdir:/WEB-INF/tags/mytags" 
  ...>

Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.