This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock exam questions 54 and 61

 
Kuppusamy Venkatasubramanian
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

In question 63,

1) <%@ taglib uri="http://www.mycompany.com/mytags" prefix="mytags" %>
2) <mytags:foo bar="abc">
3) <mytags:forEach><mytags oSomething /></mytags:forEach>
4) <jsp:setProperty name="x" property="a" value="b" />
5) <c ut value="hello" />

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??
 
Sai Patnala
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Explanation given to question 54 would be correct if "uri" element was not declared in TLD.

If you have HFSJ refer last paragraph of page: 474
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Unless it is a typo,


Yes it is a typing error. Actually that was a self closing tag.

The reason line 5 produces error is
<c ut> is part of JSTL core Library which means you got to include a taglib directive in your jsp page.

Standard Syntax:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

This is missing in that piece of code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic