Wednesday, August 12, 2009

How can i make sure User had logged in when accessing Secure Pages ?

At the beginning of each page , place this small code, or include it in a common file

HttpSession session =request.getSession(true);
if (session.getValue("username") == null) {

response.sendRedirect (response.encodeRedirectUrl("LoginPage.jsp?currentURL=productdata.jsp"));
}
else
{
// Go ahead and show the page
}


In LoginPage.jsp once the user has provided the correct logon credentials:

session.putValue("username",currentuser);
response.sendRedirect(response.encodeRedirectUrl(request.getParameter("currentURL")));

No comments:

Post a Comment