This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Please tell me the correct answer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Please tell me the correct answer" Watch "Please tell me the correct answer" New topic
Author

Please tell me the correct answer

Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
Book HFSJ
Chapter 8,Page 428

Question 6

<%
List list = new ArrayList();
list.add("a");
list.add("2");
list.add("c");

request.setAttribute("list",list);
request.setAttribute("listIdx","1");
%>
<%-- insert code here --%>

Which, inserted at line ..., are valid and evaluate to c(Choose all that apply

Options

A. ${list.2}
B. ${list[2]}
C. ${list.listIdx+1}
D. ${list[listIdx + 1]}
E. ${list['listIdx' + 1]}
F. ${list[list['listIdx']]}

The correct answer ticked was A,D,F

But option F is not working in my computer.
Is this as errata?


SCJP 5.0<br />SCWCD 1.4<br />Preparing for <b>SCEA</b>.<br /><b>"I prefer an interesting vice to a virtue that bores."</b>
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
No nothing wrong with that answer. It's correct.


Dilshan Edirisuriya SCJP1.4, SCWCD1.4, SCBCD 5
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
Nooooooooo its not working

${list[list['listIdx']]} //Wrong

if i remove the quote its working
${list[list[listIdx]]} //Right

Why?
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
I tried this one also

${list['listIdx']}

but not working.The error message is ..


javax.servlet.jsp.el.ELException: The "[]" operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.
org.apache.commons.el.Logger.logError(Logger.java:481)
org.apache.commons.el.Logger.logError(Logger.java:498)
org.apache.commons.el.Logger.logError(Logger.java:566)
org.apache.commons.el.ArraySuffix.evaluate(ArraySuffix.java:227)
org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:263)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:190)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:917)
org.apache.jsp.el_jsp._jspService(el_jsp.java:96)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
yes sorry for the answer. I didn't see it that time. When you're using double quotes you are searching inside the list. When you remove quote it just searches for an attribute. So you are correct. Someone correct me if I'm wrong.
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
That means this is an errata of HFSJ
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
The correct answers should be ...
B & D,

F. ${list[list['listIdx']]}

Here 'listIdx', it tries to convert string into int and fails...

but if it is listIdx then it searches for an attribute of that name
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
I guess so. But right now I don't have my HFSJ with me. So I'm not sure. Did you check in the errata and can anyone come up with an idea?
[ November 28, 2006: Message edited by: Dilshan Edirisuriya ]
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
No i didn't check the errata yet.
Thank you Dilshan Edirisuriya for your response
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
Thanks A Kumar
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
Thanks A Kumar
praveen sainath
Greenhorn

Joined: Nov 28, 2006
Posts: 9
Hi ppl,
I checked the HFSJ Errata, they have mentioned this error,

{420, 428} Question 6, option F;
"${list[list['listIdx']]}"
should read:
"${list[list[listIdx]]}"


Pls Reffer : http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
OK praveen sainath.
thank you.
Now i got 16 out of 18 mock questions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please tell me the correct answer
 
Similar Threads
Pg. 420 - Q.6 of HF book
Head First Servlets and JSP Chapter 8 Mock exam
Doubt in mock question on page no. 433 of Head First Servlets & JSP 2nd edition Chapter 8
Question on EL
Doubt in EL [] operator