Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in syntax for taglib uri !!

 
Prabhat Gupta
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In .tld file generally we declare the uri as
<taglib ... >
...
<uri>someURIexample</uri>
<tag>
...
...
</tag>
</taglib..>

but in K&B book,Q-3 chapter 10,i found the declaration as
<taglib>
<taglib-uri>myTags</taglib-uri>
<taglib-location>/WEB-INF/myTags.tld</taglib-location>
</taglib>

i am totally puzzled with <uri> and <taglib-uri> Can you tell me what is difference between them and where they are used ?

With thanks in advance:

Prabhat
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Different versions of JSP.
 
Ash More'
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well the format:
<taglib ... >
...
<uri>someURIexample</uri>
<tag>
...
...
</tag>
</taglib>
is used in .tld file .
this kind of mapping is called implicit mapping(which is preferred as it requires less configuration).
to refer to a tag from this file we would use:
<%@taglib uri="someURIexample" prefix="myPrefix" %>
==========================================================
whereas the format below is used in Deployment Descriptor(web.xml)
<jsp-config>
....
<taglib>
<taglib-uri>myTags</taglib-uri>
<taglib-location>/WEB-INF/myTags.tld</taglib-location>
</taglib>
....
</jsp-config>

this kind of mapping is called explicit mapping.
to refer to a tag from this tld we would use:
<%@taglib uri="myTags" prefix="myPrefix" %>


However note that: explicit mapping takes precedence over implicit mapping, therefore if the uri element in first case and taglib-uri in second case have the same content, always the explicit mapping is used.
 
Prabhat Gupta
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Bear,
Can you elaborate it more precisely?? i.e which version uses <uri> and which one uses<taglib-uri> ?
 
Prabhat Gupta
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ash,
it is very useful to know about the explicit mapping and implicit mapping.

But as per i know the <uri> name should be unique for a web-application.According to you we can use same <uri> for implicit mapping as well as explicit mapping.Does it not violate its uniqueness ??? please correct me if i am wrong.
 
Ash More'
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, i tried using the same uri in taglib-uri element of web.xml and in uri element of a .tld file (am using Tomcat 6). Didnt get any errors .My observation was: the tag pointed by taglib-uri was given preference over the tag pointed by uri element of .tld file. Thus i observed that explicit mapping was preferred over implicit mapping, no errors when same uris were used.

read also my answers in following post :
how many uri in single .tld and same uri in different tlds

Also the specification says follows:
There should be no entries in web.xml with the same taglib-uri value.

hope am not confusing you.
[ April 21, 2008: Message edited by: Ash More' ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic