猿问

我如何在 JSP 中使用 JavaScript 的会话存储?

我在spring-mvc project的过程中。登录页面当前正在进行中。问题是,我不知道如何SessionStorage使用JSP. 我需要检索我保存在SessionStorage.

我在登录后保存 ID 值。

登录.js

sessionStorage.setItem("Email",data.email);

这是我必须使用它的地方。

页眉.jsp

<a href="#" class="dropdown-toggle" data-toggle="dropdown"  ><i class="fa fa-user"></i> <span >/****sessionStorage.getItem() ***/</span></a>

我已经在控制器上保存并尝试了会话,但它没有用。

controller.java

session.setAttribute("id", email);
<a href="#" class="dropdown-toggle" data-toggle="dropdown"  ><i class="fa fa-user"></i> <span > <%session.getAttribute("id");%></span></a>

我需要你的解决方案。帮了我很多


慕沐林林
浏览 109回答 1
1回答

LEATH

使用编写JavaScript语句<script />。首先,保存到一个对象中SessionStorage,读取你保存的对象。&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="#" class="dropdown-toggle" data-toggle="dropdown"&nbsp; ><i class="fa fa-user"></i>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <script type="text/javascript">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.sessionStorage.email&nbsp; = sessionStorage.getItem("Email")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write(window.sessionStorage.email)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </script>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </a>
随时随地看视频慕课网APP

相关分类

Java
我要回答