File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on HFSJ Final Mock Exam

 
Xiaoxiao Lam
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
MInu
Ranch Hand
Posts: 517
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Chandra Sagi
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic