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

Please tell me the correct answer

 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No nothing wrong with that answer. It's correct.
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That means this is an errata of HFSJ
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No i didn't check the errata yet.
Thank you Dilshan Edirisuriya for your response
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks A Kumar
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks A Kumar
 
praveen sainath
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK praveen sainath.
thank you.
Now i got 16 out of 18 mock questions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic