• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Variables from JSTL to JSP

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
</option>

That is the basic idea of want I want to do, but the above code does not actually work...
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Always! Wait. Never. Shut up. Look at this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic