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

标签 javascript jsp servlets httpsession

这是我的 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/

相关文章:

javascript - 在带有路由器 View 的 Vue3 中使用 async setup() 时出现空白

javascript - JS (JQuery) - 未定义

javascript - Phonegap : window. 位置忘记了我的 css 和我的样式

javascript - html 间距问题-将左边距保持为可变右边距 0

macos - Safari 忽略 mime 类型

jsp - 如何在 Windows tomcat 中部署在 RHEL 5 中制作的 java tomcat 项目?

java - JSP/Servlet 和 PHP 页面之间的通信?

java - HTTP 状态 404 -/FirstSpringMVC/welcome.html

java - 访问控制-j2ee

无法解析 javax.servlet.http.HTTPServlet 导入,而包的其余部分导入正常