File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Unable to access instance vars through EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Unable to access instance vars through EL" Watch "Unable to access instance vars through EL" New topic
Author

Unable to access instance vars through EL

chetan dhewal
Ranch Hand

Joined: Nov 07, 2000
Posts: 61
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>
------------------------------


Chetan Dhewal<br />SCMAD,SCJP 1.2
Sarat Koduri
Ranch Hand

Joined: Jul 08, 2008
Posts: 83
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

Joined: Mar 27, 2003
Posts: 836
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?


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
chetan dhewal
Ranch Hand

Joined: Nov 07, 2000
Posts: 61
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

Joined: Jul 08, 2008
Posts: 83
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

Joined: May 26, 2008
Posts: 79
hi,
even am facing the same problem,but use <%@ page isELIgnored ="false" %>
for web 2.4 specification schema
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

but use <%@ page isELIgnored ="false" %> for web 2.4 specification schema

No need to do this, EL is enabled by default in 2.4.


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to access instance vars through EL