Possible Duplicate:
How to redirect to another page when already authenticated user accesses login page
If a logged in user clicks on login.jsp
page then he should be automatically redirected to his home.jsp
. Before authentication user goes to login.jsp
and after successfully authenticated by a servlet (doPost) he is redirected to home.jsp
, but when again the same user clicks on login page then he should be automatically redirected to home.jsp
instead of logging again. How can I do it in JSP/Servlet? I am setting session from that servlet after successfully authenticated.
Before login, user clicks on login.jsp
and goes to doPost()
method of servlet and goes to home.jsp
. After logged in succesfully, if user clicks again on login.jsp
then instead of going to login.jsp
, control should go directly to home.jsp
. How can I do it?
If user is signed out then only after clicking login.jsp
control will go to login.jsp
and then doPost()
of servlet and finally home.jsp
will come.
try this code in your login.jsp
if(session.getAttribute("authenticated")!=null && session.getAttribute("authenticated").equals(true))
{
response.sendRedirect("home.jsp");
}
Make the login page/action check if the user is logged in, and redirect to the home page if logged in:
if (alreadyLoggedIn) {
response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/home"));
return;
}
But you should probably not have a link to the login page in the first place if the user is already logged in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With