Reputation: 91
I doing some project based on authentication using servlet/jsp.When user log in initially using username and password where authentication takes place through login servlet,there I need to save user's email in variable ,say String email
by executing SELECT
query.
I need to access that variable from login servlet to email servlet for sending some sort of OTP to user's email.
How to achieve that using session attribute or any relevant idea??
Upvotes: 0
Views: 1723
Reputation: 1956
please use as follows. you can achieve what you need.
<%session.setAttribute( "email", "[email protected]" );%>
<%= session.getAttribute( "email" ) %>
The other way that we use.
<c:set var="email" value="[email protected]" scope="session"/>
you get this using JS:
var mail ="${email}";
Upvotes: 1
Reputation: 8495
Use session.setAttribute()
and session.getAttribute()
methods.
Read javadoc of HttpSession here.
You can refer this complete example.
Upvotes: 1
Reputation: 89
To save data in session you should use session object from http request like this:
HttpSession session = request.getSession();
session.setAttribute("email", email);
To retrieve data from session object with scriptlet use:
<%= session.getAttribute("email")%>
or
<%= request.getSession().getAttribute("email")%>
You can also use EL expression:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:out value="${sessionScope.email}"/>
Upvotes: 1