There is one trick I used to avoid character esaping - using a textarea.
let say
JSP has the following:
<textarea id='var'><%=someVariable%></textarea>
than your javasrcipt will have an access to that value using
document.getElementById('var').value
, and no escaping has to be done there. You can hide this textarea from user using CSS.
The only problem you can run into is if this variable contains "</textarea>" in it, but what are the chances? If you really worried about that you can solve that on java side.
If you need more help, please provide more info on what are you trying to do, may be show some java/javascript code examples.