tags:

views:

48

answers:

1

Hello experts,

How can I set a value using JSP 2?

I mean, if ${val} is the new version of <c:out value="${val}" />, what is the JSP 2 version of <c:set var="val" value="bla" />?

+3  A: 

I think you're confused. ${val} is not the new version of <c:out value="${val}" />. Both are Expression Language (EL) statements.*

In JSP 2, you still use <c:set var="val" value="bla" />.

http://en.wikipedia.org/wiki/JavaServer_Pages#JSP_2.0

*okay, okay, so while ${val} is an EL statement, <c:out value="${val}" /> is a JSTL tag that uses an EL expression.


The JSP 2 section of the Wikipedia article has parts copied verbatim from here.

Matt Ball
What does JSP 2 bring to the table then? Only a shortcut for the <c:out value="${val}" />? I know I can now write ${val} and it is evaluated on place instead of by the c:out tag. Is that the only change?
user0912
It's not necessarily a shortcut. JSP2 just started to support EL in template text. Prior to JSP2, EL was only evaluated in tag attribtues. The `<c:out>` does by the way one more thing: escaping XML entities. So, EL in template text does essentially the same as `<c:out value="${foo}" escapeXml="false" />`. Also note that JSTL should not be confused with EL.
BalusC
Is the `<c:out>` XML escaping equivalent to `${fn:escapeXML(foo)}` JSTL function?
Fly
@Fly yes it is (hi!)
Pointy