Assigning JSP session variable to javascript variable
843836Oct 31 2003 — edited Feb 27 2006I am trying to use "Global Variables" without the use of cookies. I though that the best way of doing it would be by the use of session objects.
code: "somefile.jsp"
<%
String value = new String("value");
session.setAttribute("name", value);
%>
...
<%
if (session.getAttribute("name") != null) {
%>
alert ("not null")
<%
String jspTemp = (String)session.getAttribute("name");
%>
var jsTemp = <%=jspTemp%>
alert (jsTemp)
<%
}
%>
I do get the first alert "not null", but I cannot seems to figure out why the second alert is not working. It seems to stall where i'm trying to assign the JSP variable with to the JavaScript variable.
I hope that someone can help me figure out this problem. Or maybe even direct me to any way to using Global Variables which can be accessed via different jsp pages.