Convert Java Variable Containing Newline To Javascript Variable
I want to convert a java variable(containing newline and other special characters) from server side sent to JSP to javascript variable. In my JSP, var test = '${educationDescriptio
Solution 1:
This issue I faced long back and very irritated with javascript as well for no proper error message.
Later I managed to solve by replacing all catridges like below from Java string.
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions"prefix="fn"%>
'${fn.replace(educationDescription,"\\r\\n|\\r|\\n", "")';
It solves the issue.
The issue here is with, we assume the problem is with new line. But sometimes the String comes with a brand new catride \r
which many people not aware.
Solution 2:
You can do something like this. Use two slashes ("\\n
")
<%
Strings="This is a \\n test";
request.setAttribute("s", s);
%>
var s="${s}";
alert(s);
Post a Comment for "Convert Java Variable Containing Newline To Javascript Variable"