Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Question no 6 Page no 420

 
KRK Gowda
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Consider the following code,
<html>
<body>
<% java.util.List list=new java.util.ArrayList ();
list.add ("1");
list.add ("2");
list.add ("3");
request.setAttribute ("list",list);
request.setAttribute ("listidx","0");
%>
Value at first postion is :${list[list['listidx']]}

Expected result is 2, but browser shows exception.

Same piece of code is available in exercise for scriptless jsps, HFJS page no 420, Question no 6. One of the correct options provided says ${list[list['listidx']]} EL expression is valid to return value present in 2nd position. but that is not working.

please tell me solution for the above problem.


Thanks and Regards,
 
Senthil Kumar
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
since the list is ArrayList,inside the [] operator should be an int or anthing that is convertible to int.
Anything else results in Exception.

if you remove the single quote around the listidx it will work.
[ October 30, 2006: Message edited by: Senthil Kumar SS ]
 
KRK Gowda
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Senthil,
i had removed the quotes from braces. it was working then.
But, what i want to know is whether the expression given in the HFJS book is correct or not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic