I need to pass a jsp string variable to a javascript function. This is usually fairly simple but I'm currently having issues because the string I'm passing contains xml characters.
This is the jsp (shortened for clarity purpose)
<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<body>
<input type="button" value="MyButton" onclick="myFunction('<c:out value="${current.xmlOutput}"/>');" />
</body>
</html>
The value in "current.xmlOutput" contains the following
<chart caption='Flight Hours' xAxisName='Flight' yAxisName='Hours' ><set label='AC908' value='126' /><set label='AC812' value='234' /><set label='AC184' value='78' /></chart>
The generated JSP source
<input type="button" value="MyButton" onclick="myFunction('< chart caption = 'Flight Hours' xAxisName = 'Flight' yAxisName = 'Hours'>< label = 'AC908' value = '126' /> < label = 'AC812' value = '234' /> < label = 'AC184' value = '78' /> </ chart >');" />
When I press the button it never calls the function. If "current.xmlOutput" contains a simple String like "Test" everything works fine. In the chrome developer tools it give me the following message "Uncaught SyntaxError: Unexpected identifier "
Also, I have a filter that does this req.setCharacterEncoding("UTF-8"); Any one know what I'm doing wrong? Any help would be appreciated.
Thanks