Accessing a JSTL variable in a JSP Scriptlet (need to replace string )
843840Oct 29 2007 — edited Apr 26 2008I 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.