可能重复: 如何重定向到另一页经过身份验证的用户访问登录页面时
Possible Duplicate: How to redirect to another page when already authenticated user accesses login page
如果已登录的用户单击login.jsp页面,则应将其自动重定向到他的home.jsp.在身份验证用户转到login.jsp之前,以及在通过servlet(doPost)成功进行身份验证之后,他被重定向到home.jsp,但是当同一用户再次单击登录页面时,应该将其自动重定向到home.jsp,而不是再次登录.如何在JSP/Servlet中完成呢?成功通过身份验证后,我将从该servlet设置会话.
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.
在登录之前,用户单击login.jsp并转到servlet的doPost()方法,然后转到home.jsp.成功登录后,如果用户再次单击login.jsp,则控件应直接转到home.jsp,而不是转到login.jsp.我该怎么办?
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?
如果用户已注销,则只有在单击login.jsp之后,控件才会转到login.jsp,然后是servlet的doPost(),最后是home.jsp.
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.
推荐答案在您的login.jsp中尝试此代码
try this code in your login.jsp
if(session.getAttribute("authenticated")!=null && session.getAttribute("authenticated").equals(true)) { response.sendRedirect("home.jsp"); }更多推荐
如果用户已经登录,则重定向到主页
发布评论