• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tag Library and Tag Library Descriptor

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got confused while reading the <taglib> element.
The <taglib-location> is where the tag library descriptor is. It should be in the WEB-INF directory or its subdirectory. Or it is in the META-INF directory or its subdirectory if the tag library descriptor is jarred.
My question is regarding the <taglib-uri>. I suppose that it is the location of the tag library. Then, what is the difference between tag library and tag library descriptor? Where is the tag library supposed to be?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me try to clarify.. Suppose you created custom actions called <MyActions:doA> and <MyActions:doB>.
There are three files at play here:
(1) The Tag Library Descriptor (TLD) file, e.g. "/context-root/WEB-INF/tlds/myActions_v1.tld". As you know, this file must specify at a minimum the <tlibversion> and <shortname> of the tag library, as well as one <tag> element per custom action (doA and doB).
(2) The JSP file, e.g. /context-root/test.jsp. This file must include a line as follows: "<%@ taglib uri="/context-root/WEB-INF/tlds/myActions_v1.tld" prefix="MyActions" %>". For the uri attribute, you actually have three options.
   (a) uri can point to the actual TLD file as given above;
   (b) uri can point to a JAR file containing the TLD file in its META-INF directory; or
   (c) uri can point to a symbolic name which is then defined in the web.xml file (see item 3a below).
(3) The Web Application Deployment Descriptor, i.e. "/context-root/WEB-INF/web.xml". If you used option 2c above, then you should provide a <taglib> element with the following sub-elements, for example: <taglib-uri>/myActions</taglib-uri> and <taglib-location>/context-root/WEB-INF/tlds/myActions_v1.tld</taglib-location>.
   (a) <taglib-uri> defines the symbolic name you are giving to your tag library, and
   (b) <taglib-location> specifies the actual TLD file or a JAR file containing the TLD file.
The advantage of this approach becomes apparent when you upgrade your tag library to a newer version, say myActions_v2.tld. With the web.xml file you can point your <taglib-location> to the new TLD file, and all your JSP files are automatically updated, since they point to the symbolic name "/myActions", not the actual TLD file path.
One caveat: Not all JSP 1.1 containers support the notation of pointing to a JAR file instead of a TLD file. If the container does not support this notation, you would have to extract the TLD file from the JAR file, place it in a directory under WEB-INF, and point to it as in item 2a above.
You had asked "What is the difference between tag library and tag library descriptor?". The descriptor defines the tag library by specifying <tag> elements for each tag that makes up the library. And each <tag> element specifies the tag handler and tag extra info classes that make up the tag implementation.
Hope this clarifies tag libraries and their descriptors. My apologies if I stated too much background info that you already know.

[This message has been edited by Miftah Khan (edited September 19, 2001).]
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Miftah, thank you very much for such a detailed explanation. The concept is crystal clear to me now. You deserve the 98% score on the Certification Exam. And thank you for sparing time to help others.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic