JSP EL: local variables

T

Timo Nentwig

Hi!

How can I access locale variables? Something like:

<%
String foo = "bar";
%>
length of foo: $(foo.length)


Timo
 
D

David Lesaffre

Timo said:
Hi!

How can I access locale variables? Something like:

<%
String foo = "bar";
%>
length of foo: $(foo.length)


Timo

Why not

<c:set var="foo" value="bar"/>
length of foo: <c:eek:ut value="${foo.length}"/>

In JSTL 2.0, something like this may work also

length of foo: ${foo.length}
 
C

Chris Smith

Timo said:
That's not EL.

Clearly not... but since EL can't do this, it seems that "not EL" is the
only remaining choice. Alternatively:

<% pageContext.setAttribute("foo", foo); %>
length of foo: ${foo.length}

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

Timo Nentwig

Chris said:
Clearly not... but since EL can't do this, it seems that "not EL" is the
only remaining choice. Alternatively:

Apparently, yes :-( I thought, EL was part of JSP2 but it's part of JSTL
only...
<% pageContext.setAttribute("foo", foo); %>
length of foo: ${foo.length}

Doesn't work. But ${pageContext.foo} doesn't work either(?)...
 
C

Chris Smith

Timo said:
Apparently, yes :-( I thought, EL was part of JSP2 but it's part of JSTL
only...

Well, EL *is* part of JSP 2.0. It's also part of JSTL. The EL is
available in JSTL even for pre-2.0 JSP versions; but EL expressions can
be placed directly in the page for JSP 2.0 pages.
Doesn't work. But ${pageContext.foo} doesn't work either(?)...

Okay, how exactly does it not work?

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

Timo Nentwig

Chris said:
Well, EL *is* part of JSP 2.0. It's also part of JSTL. The EL is

I just wonder what I should do with stuff like ${1+1}. Great, it outputs
2 but it would be somewhat more useful if I would access my fields...
Okay, how exactly does it not work?

Well, ${foo} outputs just nothing, i.e. it just does create a new foo in
pageContextImpl and ${pagecontext.foo} throws this exception:

javax.servlet.ServletException: Unable to find a value for "foo" in
object of class "org.apache.jasper.runtime.PageContextImpl" using
operator "."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top