aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes <taglib> and uri doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "<taglib> and uri doubt" Watch "<taglib> and uri doubt" New topic
Author

<taglib> and uri doubt

Swathi Kota
Ranch Hand

Joined: Jun 04, 2008
Posts: 52
Hi all,
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
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Swati ,

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:
<taglib>
<taglib-uri>/myPRlibrary</taglib-uri>
<taglib-location>/WEB-INF/tlds/PRlibrary_1_4.tld</taglib-location>
</taglib>
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” %>

Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Hi Swathi,

You can specify taglib uri in 3 ways

1) absolute or relative path to .tld file
2) logical address using web.xml mapping
3) using <uri> attribute of .tld file

Question is not saying anything about <uri> attribute. So you should consider first option.


SCJP 6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <taglib> and uri doubt