How can i access session in different jspx?
Question
I'm new to jspx and I'm not sure how I would do this. I have created a model-view-controller and have created a session in controller. Once the user has logged in, it creates the session.
HttpSession session = request.getSession();
session.setAttribute("user", username);
How can I access and display the username in the welcome.jspx page, so it would say
hello username
OTHER TIPS
Try something like this (For JSP):
<%
String username = (String)session.getAttribute("user");
out.println("<b>Welcome " + username + "!</b>");
%>
I have used scriptlet tag here. You can study about it from here .
(may be it could help someone else.)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow