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.
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.
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.
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 ]
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 ]
God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
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.
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.
"/" 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