0

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?

1 Answer 1

1

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>
2
  • In servlets we make a session,for example i made a session named sr,So while using the session in jsp why dont we use that?
    – Saumyaraj
    Apr 19, 2013 at 9:43
  • @saumyaraj Actually you are not creating a session ..you are just getting the session attached to the request and using the same in jsp also ..remember you are just using,not creating.Let me know if you still have any juggles .. :) Apr 22, 2013 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.