• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Taglib uri in TLD vs. taglib-uri in web.xml

 
Francois Groenewald
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know what the difference between the taglib-uri, which gets defined in the web deployment descriptor and the uri tag in the Tag Library Descriptor file? I am aware that taglib-uri is almost used in the same way as url-pattern would be used for servlets, but for tag libraries. What would the use be for the uri tag be?
e.g
web.xml
-------
<web-app>
<taglib>
<taglib-uri>/myTagLibrary</taglib-uri>
<taglib-location>/WEB-INF/tld/myTagLibrary.tld</taglib-location>
</taglib>
</web-app>
TLD file:
---------
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>myLibrary</short-name>
<uri>/myTagLibrary</uri>
<description>My First Tag Library</description>
<tag>
<name>myTag</name>
<tag-class>com.bw.MyTagHandler</tag-class>
</tag>
</taglib>

In the DTD description for the TLD file, it states:
-------------------------------------------------------------
Defines a public URI that uniquely identifies this version of
the taglibrary. Leave it empty if it does not apply.
-------------------------------------------------------------
What does this actually mean?
Francois Groenewald
 
Francois Groenewald
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody out there who can help me with this?
Francois
 
shweta mathur
Ranch Hand
Posts: 109
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Francois,
Placing uri in
CASE 1 ---web.xml or
CASE 2 ---TLD file
serves the same purpose.
Case1- This is called explicit mapping.The JSP container makes a mapping between the <taglib-uri> element and the <taglib-location> element.
Case2- This is called implicit mapping. The JSP container automatically creates a mapping between the specified URI <uri> and the current location of the jar file.
If the web.xml contains an explicit mapping for the same URI, then the explicit mapping takes precedence over the implicit mapping.
HTH
 
Francois Groenewald
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Shweta
Case 1: taglib-uri in web.xml
Case 2: uri in TLD file
So am I correct then to say that Case 2 is only used when deploying the custom tag library as a Jar file?
I tried something stupid so I thought:
I removed the URI from taglib-uri in web.xml and placed it in the uri tag of the TLD, hopeing that the container would use the mapping in the TLD, but it complained when I tried to reference it.
Thanks
Francois :roll:
 
shweta mathur
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, the URI in TLD file is used for automatic mapping only when the TLD file is jarred.
Actually I was just reading the specifications section -JSP 7.3.4 which does not clearly states that this doesn't work with unjarred TLD, but atleast on Tomcat it is not working. And looks like we have to interpret it in this way only.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic