Question

I have first created a login panel(index.jsp) in jsp,where user enters username and password which on submit goes to a servlet(login) which checks authenticity of user and takes it to home page after validating(home.jsp).

I want to store the user information after he/she logs in so i implemented seession in my servlet(login) as follow

response.sendRedirect("shome.jsp");
HttpSession sr=request.getSession(true);
sr.setAttribute("no", u);

(u is my string variable)

Now how can i retreive the value of no in my home.jsp?

Was it helpful?

Solution

no should be within quotes.

sr.setAttribute("no", u);

In JSP provide like this

<%
String username=(String)session.getAttribute("no");
%>

And use the string username in anywhere in JSP

Example

<H1>Your User name is: <%=username%>.</H1>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top