Pregunta

Here is my Spring MVC Controller code:

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

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

I have tried using this code:

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

But it returns null.

Thanks

¿Fue útil?

Solución

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

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top