| Author |
Doubt in Question no 6 Page no 420
|
KRK Gowda
Ranch Hand
Joined: Nov 02, 2004
Posts: 132
|
|
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
Joined: Mar 13, 2006
Posts: 264
|
|
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 ]
|
when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
|
 |
KRK Gowda
Ranch Hand
Joined: Nov 02, 2004
Posts: 132
|
|
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.
|
 |
 |
|
|
subject: Doubt in Question no 6 Page no 420
|
|
|