• 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

Doubt on HFSJ Final Mock Exam

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have doubts on the answer of Question #54 on page 827.

The Question and choices are:

Given a tag library descriptor located at /mywebapp/WEB-INF/tlds/mytags.tld, which would be the correct taglib directive? Assume mywebapp is the web application root and that there are no <taglib> tags in the deployment descriptor.

A. <%@ taglib uri="/mytags.tld" prefix="my" %>
B. <%@ taglib uri="/tlds/mytags.tld" prefix="my" %>
C. <%@ taglib uri="/WEB-INF/tlds/mytags.tld" prefix="my" %>
D. <%@ taglib uri="/mywebapp/WEB-INF/tlds/mytags.tld" prefix="my" %>

The answer given is C. But I think all of them are right. I think uri is only a name that matches the uri element declared in the tld file. So it can be any name. It doesn't need to be the location of the tld file. This is what I got when I read the book. Now I am confused. Please explain it to me if you can. Thank you so much.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If no TLD is provided, the container will have to generate an implicit tag library.
The <path> element will be set relative to the root of the web application. Answer C is the only good answer as the container will generate a <path> set to "/WEB-INF/tlds/mytags.tld"

See the pec "JSP.8.4.3 Packaging Directly in a Web Application" for more details.
 
Xiaoxiao Lam
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, if there's a TLD file and the uri element value is not the path value (As I remember, we can make it whatever we like), we should make the uri attribute of taglib equal to the uri value declared in the TLD, right?

In this question, because it doesn't mention the uri element in TLD, we should select the best one which is the full path relative to the application root. Am I right? Thank you.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I got confused with Tag Files. Please forget my first post.

The question is confusing indeed. Like you said, I would have thought that it depended on the uri set in mytags.tld.
Waiting for somebody to make this clear
[ March 13, 2006: Message edited by: Satou kurinosuke ]
 
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think all of them are correct since the 'uri' element need not to be the exact path,it can be any name.
In the question it says that there are no <taglib> tags in the deployment descriptor.In jsp2.0 you dont have to
mention <taglib> in DD ie web.xml.The above four tablib directives will search for the corresponding 'uri' element in the mytags.tld file and invoke it.

This is what my understanding....can anyone clarify?
Thanks...
[ March 13, 2006: Message edited by: Vinod NS ]
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Given a tag library descriptor located at /mywebapp/WEB-INF/tlds/mytags.tld, which would be the correct taglib directive? Assume mywebapp is the web application root and that there are no <taglib> tags in the deployment descriptor.



When you don't specify a <uri> inside the TLD, the Container will attempt to use the uri attribute in the taglib directive as a path to the actual TLD(pg 474 - last paragraph - HFSJ). In our case we haven't provided the <taglib> itself which has the <uri>, so the uri in the taglib directive which gives the correct path is the correct answer. In our case it is C.

Thanks
Chandu
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still can't get it. I thought that :

there are no <taglib> tags in the deployment descriptor.

means that there is no taglib in web.xml. (under <jsp-config>)
So that does not prevent us from setting a uri in the TLD. All answers would be true then.
 
Xiaoxiao Lam
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think if the question asks for 1 answer, only C is right and if it asks for 4 answers, all are right. :-)
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes
But don't worry, there will be no such confusion during the exam.
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"/" in uri represents the location is from context root. So I don't think all the answers are correct. I was of the impression that <taglib-uri> tag exists only in <jsp-config> of DD and <name> tag in TLD. But I need to confirm it.

Thanks
Chandu
 
Whatever you say buddy! And I believe this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic