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

Can we have 2 URIs for same TLD?

 
madhuri rajan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have read that 2 different TLDs cannot have the same URI.(since its a unique id). But my question is can a TLD have 2 URIs associated to it? Can someone please tell me what stops us from doing so.

Thanks,
Madhuri
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Madhuri,
Let me try to answer your question:
But my question is can a TLD have 2 URIs associated to it? Can someone please tell me what stops us from doing so.

The answer to your question with respect to JSP2.0 specs is, No. As per specs you can have 0 or 1 occurence of <uri> element in the TLD file. Please see diagram JSP.C-1 under JSP.C.1XML Schema for TLD, JSP 2.0 section. You will see <uri> has ? symbol next to it indication 0 or 1 occurence.
Secondly I am not sure if container will stop you from having 2 uri elements in TLD or not. This depends on the container. In Tomcat 5.0 which I use for testing purpose, I tried putting two URI elements in TLD it did not complain at deployment, however the JSP gives output only if the uri attribute of the taglib directive matches the first URI element of the TLD. The second one is ignored (I guess).
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but what happens if you use both the uri you declared in your tld file and the tld file path as uris? OK, let me explain it with an example:

You have one tld file:
/WEF-INF/example.tld

and inside of it you define

<taglib...>
...
<uri>/MyTld</uri>
...
</taglib>

Now, imagine a jsp file that contains these two taglib directives:

<%@ taglib prefix="tag1" uri="/MyTld" %>
<%@ taglib prefix="tag2" uri="/WEB-INF/example.tld" %>

I am not sure, but I think that both will be accepted. And you'll finish having two uris referring to the same tld.

It is tricky, but I fail to see where the above example is against the spec. Correct me if I am wrong.
[ May 17, 2007: Message edited by: Sergio Tridente ]
 
madhuri rajan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it. Thanks for clarifying Rancy and Sergio

Thanks,
Madhuri
 
madhuri rajan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it. Thanks for clarifying Rancy and Sergio

Thanks,
Madhuri
 
sweety singh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i tried it doing
it works the TLD file can have two uri elements
<uri>useMyTag</uri>
<uri>secondUri</uri>
<tag>
<name>advice</name>
<tag-class>com.examples.AdviceTagHandler_p467</tag-class>
<body-content>empty</body-content>

and in web.xml
1)useMyTag

<taglib>
<taglib-uri>useMyTag</taglib-uri>
<taglib-location>/WEB-INF/myFirst.tld</taglib-location>
</taglib>
<taglib>

2)secondUri

<taglib>
<taglib-uri>secondUri</taglib-uri>
<taglib-location>/WEB-INF/myFirst.tld</taglib-location>
</taglib>

note=both pointing to the same tld file
and in my jsp if i use
<%@ taglib prefix="my" uri="secondUri" %> it is working
if i give
<%@ taglib prefix="my" uri="useMyTag" %> this also is working
 
madhuri rajan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That helped sweety ... Thank you

Thanks,
Madhuri
[ September 27, 2007: Message edited by: madhuri gr ]
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sweety singh:
<uri>useMyTag</uri>
<uri>secondUri</uri>


Be careful with that. It is not what is defined in the specs. As Rancy said before (and accordingly to the tld's DTD), uri can be present 0 or 1 times.
It may work under Tomcat, but that doesn't necessarily mean it is correct. Remember you will be tested on the spec and not on Tomcat's behaviour.


[EDIT]
But this part seems perfectly legal:
Originally posted by sweety singh:
and in web.xml
1)useMyTag

<taglib>
<taglib-uri>useMyTag</taglib-uri>
<taglib-location>/WEB-INF/myFirst.tld</taglib-location>
</taglib>
<taglib>

2)secondUri

<taglib>
<taglib-uri>secondUri</taglib-uri>
<taglib-location>/WEB-INF/myFirst.tld</taglib-location>
</taglib>


So, that's why it worked: the Container will use the explicit mappings in the web.xml, and then it will try to construct mappings using the <uri> element in the tlds it founds in its 'tld search path' (under /WEB-INF but not under /WEB-INF/classes and /WEB-INF/lib, and under /META-INF in jar files placed in /WEB-INF/lib). Whenever it founds a duplicate uri, it uses the first it found first (i.e. silently discards duplicates).
[ May 18, 2007: Message edited by: Sergio Tridente ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic