wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt in question 12 of chapter 9 in SCWCD Study Guide - by David Bridgewater Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubt in question 12 of chapter 9 in SCWCD Study Guide - by David Bridgewater " Watch "Doubt in question 12 of chapter 9 in SCWCD Study Guide - by David Bridgewater " New topic
Author

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

Tiffiny Yang
Ranch Hand

Joined: Mar 29, 2006
Posts: 124
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

Joined: Mar 22, 2007
Posts: 329

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 ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Tiffiny Yang
Ranch Hand

Joined: Mar 29, 2006
Posts: 124
I tried with following, it works too.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 
Consider Paul's rocket mass heater.
 
subject: Doubt in question 12 of chapter 9 in SCWCD Study Guide - by David Bridgewater