Java Reference
In-Depth Information
In this example you define the tag library to have a URI of /djs using the taglib-uri subele-
ment. In the second subelement you point the JSP container to the location of the tld, which is
in the directory <SERVER_ROOT>/webapps/djs/WEB-INF/tlds/ and in a file named
taglib.tld .
If you have chosen to deploy the tag handlers as a jar file then, assuming that your tld is
inside the jar, you will need to replace the contents of the taglib-location subelement with a
reference pointing directly to the jar file. A code snippet that demonstrates this is listed next:
<taglib-location> /WEB-INF/lib/djs.jar</taglib-location>
Adding the taglib Directive to Your JSP
Now that you have created the tld , deployed the tag handlers, and added the tld to your Web
application it is time to make the final connection by adding the taglib directive to the actual
JSP. The taglib directive has two purposes: It tells the JSP container the location of the tld
and it names the prefix that will link the tags to the named tld. It does this with two attributes.
The first attribute is the uri . It refers to a URI that uniquely identifies the tag library. This URI
references an attribute of a taglib entry of the Web application's web.xml file. The previous
example taglib entry is listed in the following code snippet:
To reference the above Web application's taglib entry you would have to add the following
taglib directive to your JSP:
<%@ taglib uri=”/djs” prefix=”djs” %>
Notice that the uri referenced in the JSP matches the taglib-uri referenced in the web.xml
file. This tells the JSP container that this JSP references a tag library descriptor that is located
in the directory <SERVER_ROOT>/webapps/djs/WEB-INF/tlds/ and the file containing the
taglib descriptor is taglib.tld .
The second attribute defines the prefix of the tag library. This prefix is used to uniquely iden-
tify a given tag library from another tag library when parsing a JSP. In this example, the
prefix attribute is djs ; therefore a tag referencing the /djs tag library would always be begin
with djs: . The JSP container goes through the following steps when trying to resolve the loca-
tion of tag library descriptor:
Search WWH ::

Custom Search