Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ final mock exam quetion 54 - taglib and uri

 
Adrian Sosialuk
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

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 ?

Cheers,

Adrian.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a confusing question. The author replied in this thread.
 
Adrian Sosialuk
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christophe,

Thanks for your reply.

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 ...


Cheers,

Adrian
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?

Using the path is actually useful when using Tag Files, as you don't need to provide a TLD (which means there's no uri either).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic