문제

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?

도움이 되었습니까?

해결책

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top