Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Accessing a JSTL variable in a JSP Scriptlet (need to replace string )

843840Oct 29 2007 — edited Apr 26 2008
I have
<c:set var="myVar" value="..." />

I need to replace single quotes and double quotes to be escaped because I pass them into javascript functions and set them as ID for div sections
... onclick ="func('${myVar}')" ..
<div id="${myVar}">

but if the string contains ' single quotes it messes up the javascript or double quotes messes up the ID portion of the HTML tag

I know there is the JSTL function fn but I can't figure out how to do it properly in JSTL

<c:set var="myVar"
value="${fn:replace(myVar, "'", "\"")"/>

But that gets tricky since the value portion is enclosed in quotes

So I was thinking of using a Scriptlet part instead.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 24 2008
Added on Oct 29 2007
5 comments
1,157 views