I am accessing the JSP Variable in Javascript and printing it(this is exact context in my code). However, it is showing “Excepted ;” at line 9(line 9 code is document.write(na);)..
Is there any way to access the below format JSP string in javascript?
<%
String name = "Java Beans \"is\" a reusable component";
%>
<html>
<head>
<script>
var na = "<%=name%>";
document.write(na);
</script>
</head>
</html>
You need to use single quotes to wrap your variable – the value contains double-quotes which will break the output, as JavaScript will see:
Instead do this:
…note the single quotes.
Cheers