我使用servlet / jsp进行基于身份验证的项目。当用户最初使用用户名和密码登录时,通过登录servlet进行身份验证,我需要将用户的电子邮件保存在变量中,比如String email
执行SELECT
查询。
我需要从登录servlet访问该变量到电子邮件servlet,以便将某种OTP发送到用户的电子邮件。
如何使用session属性或任何相关的想法来实现?
答案 0 :(得分:1)
答案 1 :(得分:1)
请使用如下。你可以实现你所需要的。
/Users/*username*/Desktop/Archives/
我们使用的另一种方式。
ARCHIVES="$HOME/Desktop/Archives/"
echo "$ARCHIVES"
#expands to "/Users/*username*/Desktop/Archives/"
mkdir "$ARCHIVES/test/"
#creates the 'test' directory
你使用JS得到这个:
<%session.setAttribute( "email", "test@gmail.com" );%>
<%= session.getAttribute( "email" ) %>
答案 2 :(得分:1)
要在会话中保存数据,您应该使用http请求中的会话对象,如下所示:
HttpSession session = request.getSession();
session.setAttribute("email", email);
使用scriptlet从会话对象中检索数据:
<%= session.getAttribute("email")%>
或
<%= request.getSession().getAttribute("email")%>
您也可以使用EL表达式:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:out value="${sessionScope.email}"/>