[OT?]JSP: Escape EL expressions

A

Ashton

I am trying to write some JSP code that uses JSTL. However, I also need
the output page to contain the actual string:

<c:eek:ut value="${param.author}"/>

I've tried HTML tags, using the string as a value in another c:eek:ut,
setting the string into a JSTL variable, but nothing seems to protect
the EL expression. I even tried putting it in its own file and using
jsp:include, but it looks like that also happens before tag evaluation.

The closest I've got is by using...

<c:eek:ut value='<c:eek:ut value="$\{param.author}"/>' escapeXml='false'/>

....but that's a bit too literal and doesn't see the '\' as an escape
character...inserts it verbatim in the response.

What am I missing?

(I suspect I could use entities to make the output *look* right in a
browser, but that's not the goal.)
 
A

Ashton

Ashton said:
The closest I've got is by using...

<c:eek:ut value='<c:eek:ut value="$\{param.author}"/>' escapeXml='false'/>

Following up my own post....

Of course as soon as I posted that, a solution came to me. If I write
the text I want in chunks, without any one chunk having an EL
expression, no evaluation happens. As in:

<c:eek:ut value='<c:eek:ut value="$' escapeXml='false'/><c:eek:ut
value='{param.author}"/>' escapeXml='false'/>

However, if anyone has a more elegant solution, I'd be happy to hear
about it. Thanks.
 
C

Christophe Vanfleteren

Ashton said:
Following up my own post....

Of course as soon as I posted that, a solution came to me. If I write
the text I want in chunks, without any one chunk having an EL
expression, no evaluation happens. As in:

<c:eek:ut value='<c:eek:ut value="$' escapeXml='false'/><c:eek:ut
value='{param.author}"/>' escapeXml='false'/>

However, if anyone has a more elegant solution, I'd be happy to hear
about it. Thanks.

From the JSP 2 spec:

For literal values that include the character sequence ${, JSP 2.0 provides a
way to escape them by using the sequence ${'${'. For example, the following
character sequence is translated into the literal value ${expr}:

${'${'}expr}
 

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
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top