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?
SCJP 1.4<br />SCWCD 1.4
Nikhil Jain
Ranch Hand
Joined: May 15, 2005
Posts: 383
posted
0
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.
SCJP 1.4, SCWCD 1.4, SCBCD 1.5
Khaled Mahmoud
Ranch Hand
Joined: Jul 15, 2006
Posts: 360
posted
0
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.
SCJP, SCJD,SCWCD,SCDJWS,SCEA 5 MCP-C#, MCP-ASP.NET - http://www.khaledinho.com/ Life is the biggest school
Dirk Lombard
Greenhorn
Joined: Jul 27, 2005
Posts: 18
posted
0
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
Joined: May 15, 2005
Posts: 383
posted
0
Hey, Check the other for the same topic on the forum...
Kiaama Liames
Ranch Hand
Joined: Jun 30, 2006
Posts: 52
posted
0
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 ]
scjp 1.4<br />scwcd 1.4
Dirk Lombard
Greenhorn
Joined: Jul 27, 2005
Posts: 18
posted
0
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
Joined: Jun 30, 2006
Posts: 52
posted
0
<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
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.