문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top