使用JavaScript访问HttpSession中存储的值
以下是我的Spring MVC控制器代码:使用JavaScript访问HttpSession中存储的值,javascript,jsp,servlets,httpsession,Javascript,Jsp,Servlets,Httpsession,以下是我的Spring MVC控制器代码: session.setAttribute("YourProperty", "arg1"); 如何使用JavaScript访问HttpSession中存储的属性 我已尝试使用此代码: var property = <%=session.getAttribute("YourProperty")%>; alert(property); var属性=; 警报(财产); 但它返回null 谢谢var property=“”; var prope
session.setAttribute("YourProperty", "arg1");
如何使用JavaScript访问HttpSession中存储的属性
我已尝试使用此代码:
var property = <%=session.getAttribute("YourProperty")%>;
alert(property);
var属性=;
警报(财产);
但它返回null
谢谢var property=“”;
var property="<%=session.getAttribute("MyProperty")%>";
alert(property);
警报(财产);
属性名称应该匹配,因为您要添加字符串,所以应该添加
“
绕过
,代码将首先警告arg1
您对属性的分配不安全。”。如果是字符串,代码将失败。另一件事是您在会话中设置了属性myProperty,但您得到的属性不匹配。很抱歉,这是我的错误。现在我已编辑了我的问题。。