This is regarding the questions 54 and 63 in HFSJ mock exam.
Question 54, Given a tag library descriptor at /mywebapp/WEB-INF/tlds/mytags.tld, which could be the correct taglib directive? Assume mywebapp is the web application root and 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" %>
My answer was all(a,b,c,d) because in jsp 2.0 the uri is not the pointer to the actual tld whereas the container loads all the tlds during startup and during the tag call based on the action used with prefix the appropriate tag class is called. But the answer given was C citing, it is the actual localtion of the tld file. Which one is correct??
Assuming the above lines are from a complete JSP, which lines will generate error.
My doubt is whether can we use reserved variables like forEach as taghandler class calls. My answer was lines 3 and 4 will generate errors but according to HFSJ, the answer is line 5 will only generate error..Any idea??
SCJP1.4, SCBCD 1.3, SCWCD 1.4, SCEA 5, JLPT-N3
Second question: Unless it is a typo, second option does not have a closing tag or />. I would assume that would be error. Third option is perfectly valid like infinite loop, probably causes runtime error depending on what the body of forEach tag is doing. Last option is also syntactically valid.
Coming to taglib, uri part: J2EE Tutorial says, it has to start with /WEB-INF/<tldlocation>. You are right, uri in taglib is something that uniquely identifies the tag library.