• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final mock exam question 54

 
Dirk Lombard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this question is misleading.

The question:
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.

Possible answers:
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" %>

Correct answer according to the book is C.

But I think it can be any of them because page 475 of HFSJ says the container automatically builds a map between TLD files and <uri> names, so that when a JSP invokes a tag, the Container knows exactly where to find the TLD that describes the tag. So in the new (JSP2.0) no <taglib> entry in the DD. In my opinion the question should state that it is refering to the old spec before JSP 2.0. So if I right exam tomorrow and I get the same question what is the correct answer?
 
Nikhil Jain
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many threads on this issue. Kindly Search. By the way. The answer to this question is that, what if you have to do the mapping by yourself??

I mean if there is no URI tag in tld the container searches for the mapping. If it searches, then what would be the answer. Don't worry. I don't think that there would be such misleading question in the exam.
 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the uri tag in the tld mandatory??
And when someone imports a tag library <%@ taglib uri="someuri" %>
this someuri has to be the sameone declared in the tld file.
 
Dirk Lombard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 474 of the HFSJ says there you do not have to specify a <uri> but this is considered bad practice not to do it.In that case the <uri> in the taglib declaration will be used by the container as a path to the actual TLD.

I did read through all the previous post about question 54 problem before I posted my message but I did not find a satisfactory answer. The question in the book does not say that the <uri> was not specified and I still feel the answer in the book is wrong.
 
Nikhil Jain
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, Check the other for the same topic on the forum...
 
Kiaama Liames
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the value of the uri attribute of the taglib does not match any of the <taglib-uri> entries , the following three possibilities arise:

If the uri is an absolute URI(both protocol and username), then it is an error

If the uri is a root-relative URI(that starts with a /),it is assumed to be relative to the web application's root directory

If the specified uri is a nonroot relative URI(does not start with a / and no protocol and host name), it is assumed to be relative to the current JSP page.

In this case B , C , D are root relative URIs so the location would be <doc-root>/WEB-INF/tlds/mytags.tld this is equivalent to /mywebapp/WEB-INF/tlds/mytags.tld so C is the correct answer.

A is incorrect because as the uri is a nonroot relative URI, it is assumed to be relative to the current JSP page the engine will except to find the mytags.tld at /mywebapp/jsp/mytags.tld will is incorrect

B is incorrect as the engine will try to find the tld at /myuwebapp/tlds/mytags.tld which would be incorrect

D would be incorrect as the engine will try to find the tld at /mywebapp/mywebapp/WEB-INF/tlds/mytags.tld which would be wrong
[ September 21, 2006: Message edited by: Kiaama Liames ]
 
Dirk Lombard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kaaima I agree with what you said. But in the question it is not mentioned that there is no matching <uri> element. In JSP 2.0 the container will load the tld files automatically if they are in the right directory according to the specification and I assumed that to be the case.
 
Kiaama Liames
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


<taglib> element associates one URI with one location since <taglib-uri> is a subelement so it is not present

The container creates a implicit mappping mapping in case of JAR files. The TLD file should be present in the JAR , and should be named taglib.tld which is not the case here
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic