使用JavaScript访问存储在HttpSession中的值

Accessing values stored in HttpSession using JavaScript

本文关键字:HttpSession JavaScript 访问 存储 使用      更新时间:2023-09-26

这是我的Spring MVC控制器代码:

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