Access values ​​stored in HttpSession using JavaScript

Here is my Spring MVC controller code:

session.setAttribute("YourProperty", "arg1");

How can I access an attribute stored in an HttpSession using JavaScript?

I tried using this code:

var property = <%=session.getAttribute("YourProperty")%>;
alert(property);

But it returns null.

thanks

+4
source share
1 answer
var property="<%=session.getAttribute("MyProperty")%>";
alert(property);

Attribute names must match, and since you are adding a line, you must add "around <%=session.getAttribute("MyProperty")%>and the code will warn arg1.

+4
source

All Articles