使用Shiro登录后重定向到上次访问的页面 [英] Redirect to the last page visited after login using Shiro

查看:172
本文介绍了使用Shiro登录后重定向到上次访问的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用apache shiro登录并重定向到最后访问的页面的更好方法是什么?

What is the better way to login with apache shiro and redirect to the last page visited?

我只有这个:

SecurityUtils.getSubject().login(new UsernamePasswordToken(username, password, rememberMe);

推荐答案

您可以通过WebUtils.getAndClearSavedRequest()获取上次访问的页面.您可以使用标准的ExternalContext#redirect()或OmniFaces Faces#redirect()重定向到它,它们都支持重定向JSF ajax请求.

You can get the last visited page by WebUtils.getAndClearSavedRequest(). You can redirect to it using standard ExternalContext#redirect() or OmniFaces Faces#redirect() which both supports redirecting JSF ajax requests.

SecurityUtils.getSubject().login(new UsernamePasswordToken(username, password, rememberMe));

SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(Faces.getRequest());

if (savedRequest == null) {
    Faces.redirect("homepage.xhtml");
} else {
    Faces.redirect(savedRequest.getRequestUrl());
}

这篇关于使用Shiro登录后重定向到上次访问的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆