I got confused with a mock exam question in HFSJ 1st edition. My understanding of uri attribute of <@taglib ..> directive is that
1. uri need not be an actual location. It can be a logical name and all that matters is that the <uri> in TLD and uri in taglib directive should match.
2. Uri can be used as a location when there is no <uri> element defined in TLD.
3. From JSP 2.0 we need not enter <taglib> element in DD. The container automatically builds a map.
But in one of the mocks i HFSJ 1st edition, I got a question:
As per my understanding above answer should be a,b,c,d because whatever the URI is (irrespective of taglib entry in DD) all that is needed is that uri in taglib and TLD match. But answer to this question is given as C.
The explanation says :
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
Can anybody explain ? i have my exam date coming very soon and i am really confused with this. Please help me
SCJP 6, SCWCD 5
Success is how high you bounce when you hit bottom
Though the answer C explanation is misleading. This is from JSP spec check this out. The point to note is the fallback rule mentioned at the last
The following describes how to resolve a taglib directive to compute the TLD
resource path. It is based on the value of the uri attribute of the taglib directive.
If uri is abs_uri, an absolute URI
Look in the taglib map for an entry whose taglib_uri is abs_uri. If found, the
corresponding taglib_location is the TLD resource path. If not found, a translation
error is raised.
• If uri is root_rel_uri, a relative URI that starts with /
Look in the taglib map for an entry whose taglib_uri is root_rel_uri. If found,
the corresponding taglib_location is the TLD resource path. If no such entry is
found, root_rel_uri is the TLD resource path.
The use of relative URI specifications in the taglib map enables very short
names in the taglib directive. For example, if the map is:
then it can be used as:
<%@ taglib uri=”/myPRlibrary” prefix=”x” %>
Finally, the fallback rule allows a taglib directive to refer directly to the TLD. This arrangement is very convenient for quick development at the expense of less
flexibility and accountability. For example, in the case above, it enables:
<%@ taglib uri=”/WEB-INF/tlds/PRlibrary_1_4.tld” prefix=”x” %>