This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
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" %> E) /mywebapp/WEB-INF/tlds/mytags.tld is NOT a valid location for a tag library descriptor, so none of these will work.
The correct answer according to the HFSJ is C stating:
Option C is correct because, in the absence of a <taglib> element in the DD, the URI must be a full path relative to the application root.
I really don't understand it. Earlier you can read that URI is not a real path to the tld file and now they write it is. You don't have to write any <taglib> elements in the DD and it will still work (assuming there is a tld with matching URI whatever it is and it's in the default location). Is it a mistake ?
Yes - I looked through JSP spec and IMHO the question is wrongly formed.
1) First of all, you don't have to use taglib element in DD at all 2) The important thing is that URI matches, no matter what it is. So even though you don't have the taglib element in the DD, it doesn't have to be path. 3) And here the thing that I don't quite understand - you can provide path to the existing tld file which will work, but why would anybody do that ? I mean you have to provide URI or path anyway, so unless someone is lazy and have URI longer than path then that's the only reason I can see of using that ...