这是我的 Spring MVC Controller 代码:
session.setAttribute("YourProperty", "arg1");
如何使用 JavaScript 访问存储在我的 HttpSession 中的属性?
我试过使用这段代码:
var property = <%=session.getAttribute("YourProperty")%>;
alert(property);
但它返回 null。
谢谢
最佳答案
var property="<%=session.getAttribute("MyProperty")%>";
alert(property);
属性名称应该匹配,因为您要添加一个字符串,所以您应该添加 "
周围<%=session.getAttribute("MyProperty")%>
, 代码会提醒 arg1
.
关于javascript - 使用 JavaScript 访问存储在 HttpSession 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20139634/