Within my JSP, I have a string value stored in ${state.status.code} that I need to pass to a JavaScript function when a table element is clicked using onClick to trigger the showStatus function. Here is how I have attempted to achieve this:
<c:set var="statusString" value="${state.status.code}" />
<td id="${rowId}"><a href="#"
class="pClass"
onClick="showStatus('${statusString}')>
Here be status
</a>
The issue I am facing is that the statusString may contain characters like double quotes or apostrophes, and I am struggling to escape them properly. I have experimented with different approaches within the c:set tag, such as using fn:replace with ' and ", StringEscapeUtils.escapeJavaScript(statusString), and fn:escapeXml(statusString). While one of these methods may work, I believe I may not have implemented it correctly, enclosed it in the wrong characters, or not handled it correctly.
One workaround I thought of is replacing these characters with a unique string like "!#$#!" and then substituting them back when displaying the HTML popup in the showStatus function. However, this solution seems unnecessarily complex for what should be a simple problem. Is there a better way to handle this issue?