How can I read/access a JSP variable from JavaScript?
Advertisement
Answer
alert("${variable}");
or
alert("<%=var%>");
or full example
<html> <head> <script language="javascript"> function access(){ <% String str="Hello World"; %> var s="<%=str%>"; alert(s); } </script> </head> <body onload="access()"> </body> </html>
Note: sanitize the input before rendering it, it may open whole lot of XSS possibilities