Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to access instance vars through EL

 
chetan dhewal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to access the array declared in the same jsp page through EL.
I cant see any exception coming but, there is no out put as well, tried to print the value of the array through <%= str[0] %> and its coming. Please advice...

code
------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%! public String[] str = {"1","2","3"}; %>
<br>
Value is: ${str[0]}
</body>
</html>
------------------------------
 
Sarat Koduri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.. The array string you have declared through Jsp declaration will NOT be available to the Expression Language and the point is you can not declare variables like this in EL.. you just need to get the variables from some other places like variables stored in different scopes..

Hope you got it.

PLEASE CORRECT ME IF I AM WRONG. :roll:
[ September 22, 2008: Message edited by: Sarat Koduri ]
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variables need to be bound into a scoped attribute (page, request, session or application scope) in order to be accessible from EL. You would need something like:
<% public String[] str = {"1","2","3"};
pageContext.setAttribute("str",str);
%>
Why are you using a <%! declaration too, rather than a <% scriptlet?
 
chetan dhewal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Alright, that means, i have to "atleast" put all my instance vars which i want to use into pageContext scope to access them; any other way out without putting them into scope?
[ September 22, 2008: Message edited by: chetan dhewal ]
 
Sarat Koduri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chetan... i just want to put a few words over your question..

some where i read like... EL is meant to be used to access or manipulate the already available variables but there is no way you can directly declare variables through El ....

This is weird but true. beleive me... :roll:
[ September 23, 2008: Message edited by: Sarat Koduri ]
 
shabarish vai
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
even am facing the same problem,but use <%@ page isELIgnored ="false" %>
for web 2.4 specification schema
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but use <%@ page isELIgnored ="false" %> for web 2.4 specification schema

No need to do this, EL is enabled by default in 2.4.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic