• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Taglib Question (enthruware)

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
There is a question:

The tag library descriptor shown in the exhibit has been kept in /WEB-INF/mytlds/tld1.tld folder of the webapplication. What should be inserted at line 6 so that line 7 will work as expected?

5. ...
6. <<INSERT CODE HERE >>
7. <mytags:tag1 />


Assume that the application can be accessed through http://localhost/myapp



And 2 from 4 answers:
b) <%@ taglib prefix="mytags" uri="/WEB-INF/mytlds/tld1.tld" %>
c) <%@ taglib prefix="mytags" uri="http://abt.com/tld/mytaglib" %>

For me right answer is C - in taglib we have uri: http://abc.com/tld/mytaglib
But enthruware claims that good answer is b.

Ok - for me it's almost ok, but /WEB-INF/mytlds/tld1.tld is not uri, but taglib-location ...
Who can explain me this ?

ps. - Ok, answer c is wrong, because of "typo" - in taglib we have http://abC and in uri is http://abT
So for me there is no rigth answer ....
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ok - for me it's almost ok, but /WEB-INF/mytlds/tld1.tld is not uri, but taglib-location ...
Who can explain me this ?



By default container searches for 'tld' files under 'WEB-INF' folder and its sub directories. We don't need to mention exact location like above. If we put there is no wrong.

In future if we changed the location of 'tld' file to some where else, we have to modify the change in 'taglib' directive. This way is not flexible approach.
 
Łukasz Suchecki
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Yes - I know about that, but it's taglib-location what you are talking about.
And the question was about : <%@ taglib prefix="mytags" uri="/WEB-INF/mytlds/tld1.tld" %>
Everywhere I read uri was the name of the taglib defined in tld file. And here it's taglib location.
And what if we create taglib with uri "/WEB-INF/mytlds/tld1.tld", put it into file /WEB-INF/mytlds/tld2.tld and in taglib directive we add:
<%@ taglib prefix="mytags" uri="/WEB-INF/mytlds/tld1.tld" %> ?
Which tag will have prefix mytags ? That in file tld1.tld or that in file ltd2.tld but with uri = /WEB-INF/mytlds/tld1.tld ?
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Łukasz

Sorry, I have overlooked it.

And what if we create taglib with uri "/WEB-INF/mytlds/tld1.tld", put it into file /WEB-INF/mytlds/tld2.tld and in taglib directive we add:
<%@ taglib prefix="mytags" uri="/WEB-INF/mytlds/tld1.tld" %> ?
Which tag will have prefix mytags ? That in file tld1.tld or that in file ltd2.tld but with uri = /WEB-INF/mytlds/tld1.tld ?



Here uri="/WEB-INF/mytlds/tld1.tld" attribute signifies the name of the 'uri' in 'tld2.tld' like <uri>/WEB-INF/mytlds/tld1.tld</uri>.
Container will searches for tld files in the predefined locations and finds the 'tld2.tld' file and sees its 'uri' element and if match found, then it takes this as valid tld file. Here '/WEB-INF/mytlds/tld1.tld' is just name, nothing to find the location. Prefix 'mytags' will be valid for 'tld2.tld' only.

 
Łukasz Suchecki
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, but I dont understand.
In tld file we have: <uri>http://abc.com/tld/mytaglib</uri>;
and enthruware claim that to use that tag we use in JSP:
<%@ taglib prefix="mytags" uri="/WEB-INF/mytlds/tld1.tld" %>

For me it's wrong ...
ps. maybe I'm not clear

As I understand uri in taglib directive is matched with uri in TLD file (and TLDs files are searched for in WEB-INF and subs, or in placec declared byl taglib element in web.xml).
In this case enthruware matches uri in taglib directive with path to the existing TLD file.
 
Ranch Hand
Posts: 48
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!


In tld file we have: <uri>http://abc.com/tld/mytaglib</uri>;
and enthruware claim that to use that tag we use in JSP:
<%@ taglib prefix="mytags" uri="/WEB-INF/mytlds/tld1.tld" %>



In this case the taglib directive should be used as:

<%@ taglib prefix="mytags" uri="http://abc.com/tld/mytaglib" %>


There is also one way in which the uri could be used as a location, but its considered as a bad practice. If you dont specify the <uri> inside the TLD , the container will attempt to use the uri attribute in the taglib directive as a path to the actual TLD.(But hard coding the location of the TLD is really a bad idea.)

But the TLD give here has a

<uri>http://abc.com/tld/mytaglib</uri>;

. so option

b) <%@ taglib prefix="mytags" uri="/WEB-INF/mytlds/tld1.tld" %>

is not a right option.


According to the above discussion both the options are wrong.


Thanks,
Nitin.
 
Łukasz Suchecki
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And we are all wrong
I've tested it on tomcat and it seems to work like that:
- find tld with uri section = uri from directive in TLD files inside WEB_INF (and subdirectories)
- find tld with uri section = taglib-uri section of web.xml

If both above fails it seems to try to look for TLD file named like uri.
Yes, I know that Head First says that uri is name and it's not connected in any way with physical location of the file. But enthruware claim that it is, and my tests shows that they are right.
 
Patil Niteen
Ranch Hand
Posts: 48
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If both above fails it seems to try to look for TLD file named like uri.
Yes, I know that Head First says that uri is name and it's not connected in any way with physical location of the file. But enthruware claim that it is, and my tests shows that they are right.




A more clear explanation :-

According to jsp specs :

JSP.7.3.6.2 Computing the TLD Resource Path
The following describes how to resolve a taglib directive to compute the TLD
resource path. It is based on the value of the uri attribute of the taglib directive.
*If uri is abs_uri, an absolute URI
Look in the taglib map for an entry whose taglib_uri is abs_uri. If found, the
corresponding taglib_location is the TLD resource path. If not found, a translation
error is raised.
* If uri is root_rel_uri, a relative URI that starts with /
Look in the taglib map for an entry whose taglib_uri is root_rel_uri. If found,
the corresponding taglib_location is the TLD resource path. If no such entry is
found, root_rel_uri is the TLD resource path.
* If uri is noroot_rel_uri, a relative URI that does not start with /
Look in the taglib map for an entry whose taglib_uri is noroot_rel_uri. If found,
the corresponding taglib_location is the TLD resource path. If no such entry is
found, resolve noroot_rel_uri relative to the current JSP page where the directive
appears; that value (by definition, this is a relative URI specification that starts
with /) is the TLD resource path. For example, if /a/b/c.jsp references
../../WEB-INF/my.tld, then if there is no taglib_location that matches
../../WEB-INF/my.tld, the TLD resource path would be /WEB-INF/my.tld.

So, the container uses the fallback rule and allows a taglib directive to refer directly to the TLD.
Thanks,
Nitin.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic