• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

EL behaviour

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello ranchers,
I am studying JSP EL topic and facing a peculiar problem. I am running a simple JSP as shown below
<%@ page isELIgnored = "false" import= "java.util.*" %>
<BODY>
<%
ArrayList list=new ArrayList();
list.add("hi");
list.add("hello");
request.setAttribute("list",list);//adding list to request
%>
${list[3]}//EL to dispaly the list from above
<%
//ArrayList list1=(ArrayList)request.getAttribute("list");
//out.println(list1.get(3));
%>
From the above code I thought it will throw IndexOutOfBoundsException,but it is showing blank page as output. If I access the attribute by uncommenting below lines,it throws right exception.
//ArrayList list1=(ArrayList)request.getAttribute("list");
//out.println(list1.get(3));

Is it container specific? I am using tomcat 5.5
Pls help me in understanding this behaviour
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does the JSP Specification section regarding the EL have to say about this situation?
 
manish agarkhed
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.As suggested by you,I looked into the EL specifications and it says

If value-a is a List or array:
� Coerce value-b to int (using coercion rules)
� If coercion couldn't be performed: error
� Then, if value-a.get(value-b) or Array.get(value-a, value-b) throws ArrayIndexOutOfBoundsException
or IndexOutOfBoundsException: return null
� Otherwise, if value-a.get(value-b) or Array.get(value-a, value-b) throws other
exception, error

From above ,my perception is I should able to print NULL,but it is showing a blank page. Pls let me know your thought.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It says "return null" not "print null".
 
manish agarkhed
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got your point, thank you very much for your help
 
Good night. Drive safely. Here's a tiny ad for the road:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic