• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in Question no 6 Page no 420

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic