jQuery in Action, 3rd edition
The moose likes JSP and the fly likes Variables from JSTL to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Variables from JSTL to JSP" Watch "Variables from JSTL to JSP" New topic

Variables from JSTL to JSP

Bloo Barton
Ranch Hand

Joined: May 09, 2005
Posts: 63
How can I access my variable that is defined in JSTL from standard JSP? How about the opposite (from JSP to JSTL)?

I tried the following

<c:set var="a" value="5" />

Here I will try to output a :: <%= a%>.

That would give me an error that 'a' is not defined.
Yes if I output it using JSTL
<c ut value="${a}" />

That of course would work fine.
Also, is it possible for me to embed HTML tags as part of a variable so I can dynamically generate forms?

For example, what I would like to do is something like this...

<c:set var="varX" value="<option value=""" />
<!-- not sure if "" is the correct way to escape a quotation?, this is how I would do it in ASP; I'm still new to JSP though... -->

<c:set var="varY" value="${a}" />
<c:set var="varZ" value=""">" />

<c ut value="${varX}${varY}${varZ}" />
Some Text Here

That is the basic idea of want I want to do, but the above code does not actually work...
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

One of the whole purposes of the EL and JSTL is to eliminate scripting in the pages, so it's no surprise that they don't play along well together. When you "set" a variable using <c:set/> you are not creating a scripting variable, but rather a scoped variable.

Now, you can retrieve the scoped variable from its appropriate scope using the getAttribute() method and store it in a scripting variable, but I'd question why you are mixing JSTL/EL and scripting on the same page.

Quotes are escaped in EL expressions in the same way that they are in Java expressions, with the "\" character.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link: http://aspose.com/file-tools
subject: Variables from JSTL to JSP
It's not a secret anymore!