Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Assigning JSP session variable to javascript variable

843836Oct 31 2003 — edited Feb 27 2006
I 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 27 2006
Added on Oct 31 2003
9 comments
1,634 views