I am having an issue with using Spring’s mechanism to fill in an array of strings if one of the strings contain a new line.
The jsp code looks like this:
function foo() {
var strs = new Array();
<c:forEach items"${strItems}" var="s">
strs.push("${s}");
</c:forEach>
}
After being rendered for the client, the javascript becomes:
function foo() {
var strs = new Array();
strs.push("item1");
strs.push("item2
with
newlines
in it.");
strs.push("item3");
}
Which is now invalid javascript. I need to keep the endlines in the string, so I cannot scrub the data of them. I am unsure of what to do, any suggestions would be a big help.
Thanks.
There are libs to do the type conversion:
And all you have to do is to let them serialize your array, and output the result as a string.