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

EL behaviour

 
manish agarkhed
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says "return null" not "print null".
 
manish agarkhed
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got your point, thank you very much for your help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic