• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in question 12 of chapter 9 in SCWCD Study Guide - by David Bridgewater

 
Tiffiny Yang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the result of accessing the following tag file? (Line numbers are for reference only and should not be considered part of the tag file source.) (Choose one.)
01 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jst1/core" %>
02 <c:set var="character">65</c:set>
03 <c:forEach begin="1" end="10" varStatus="loopCount" >
04 <% char c = (char)
Integer.parseInt (pageContext.getAttribute("character").toString ());
05 pageContext.setAttribute("displayCharacter", new Character(c));
07 %>
08 ${displayCharacter}
09 <c:set var="character">${character + 1}</c:set>
10 </c:forEach>
A.Translation error at line 1
B.Translation error at line 4
C.Translation error at line 9
D.Run-time error at line 9
E.Output from tag file of A B C D E F G H I J

The answer is B. with explaination:
A translation error occurs as soon as the JSP scriptlet begins at line 4. You are not allowed to embed scriptlets or scriptlet expressions (or any other sort of direct Java language syntax) in a tag file.

-----------------
But I run it, it won't work. I get message:
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jst1/core cannot be resolved in either web.xml or the jar files deployed with this application

So, it runs if use
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
to replace
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jst1/core" %>
and the result is A B C D E F G H I J


Thanks.
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tiffiny,

Originally posted by Tiffiny Yang:
The answer is B. with explaination:
A translation error occurs as soon as the JSP scriptlet begins at line 4. You are not allowed to embed scriptlets or scriptlet expressions (or any other sort of direct Java language syntax) in a tag file.


That statement seems wrong to me. You cannot use any kind of scriptlet inside the body of a tag file when you invoke it from your JSP (body-content must be at most "scriptless"). This is the same as with SimpleTags: both use a JspFragment!

Originally posted by Tiffiny Yang:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jst1/core" %>


Have you tried <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>?
[ April 18, 2007: Message edited by: Sergio Tridente ]
 
Tiffiny Yang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried with following, it works too.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic