如果用户已经登录,则重定向到主页

编程入门 行业动态 更新时间:2024-10-09 04:19:10
本文介绍了如果用户已经登录,则重定向到主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: 如何重定向到另一页经过身份验证的用户访问登录页面时

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"); }

更多推荐

如果用户已经登录,则重定向到主页

本文发布于:2023-11-01 11:09:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549176.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   用户   主页

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!