redirect - 控制器中的操作后如何精确重定向页面(grails)
问题描述
所以我有注销功能,我想在注销后返回登录页面。我的控制器名为 LoginController.groovy。但是注销后它只刷新页面而不是直接它。顺便说一句,它是由 spring 安全插件创建的。
/**
* go to login page when successful logout.
*/
def logout() {
if(request.logout()) // Logout current user
redirect(controller: 'Login', action: 'index') // Redirect to the login page
}
/**
* Default action; redirects to 'defaultTargetUrl' if logged in, /login/auth otherwise.
*/
def index() {
if (springSecurityService.isLoggedIn()) {
redirect controller:'Login', action:'homepage'
}
else {
redirect action: 'auth', params: params
}
}
/**
* Show the login page.
*/
def auth() {
def config = SpringSecurityUtils.securityConfig
if (springSecurityService.isLoggedIn()) {
//redirect uri: config.successHandler.defaultTargetUrl
redirect controller:'Login', action:'homepage'
}
String view = 'auth'
String postUrl = "${request.contextPath}${config.apf.filterProcessesUrl}"
render view: view, model: [postUrl: postUrl,rememberMeParameter: config.rememberMe.parameter]
}
解决方案
但是注销后它只刷新页面而不是直接它。顺便说一句,它是由 spring 安全插件创建的。
你有这个:
def logout() {
if(request.logout())
redirect(controller: 'Login', action: 'index')
}
这相当于:
def logout() {
if(request.logout()) {
redirect(controller: 'Login', action: 'index')
} else {
render view: 'logout', model: [:]
}
}
这意味着重定向只会在.logout()
返回true
(或评估为 Groovy 真相的东西)时发生。
推荐阅读
- sql - 我在这个 SQLite 模式中有冗余索引吗?
- asp.net-core - Python 请求和 ASP.Net Core API 之间的 Post 值始终为空
- vert.x - Vert.x 网络流式传输 http 请求正文
- reactjs - 如何读取嵌套对象 React Redux 的属性?
- php - 致命错误:未捕获的 Elasticsearch\Common\Exceptions\BadRequest400Exception
- angular - Angular CLI 动态设置 APP_BASE_HREF
- python - 无法从烧瓶 api 的反应 js 中获得所需的响应
- sql - 如何使用 PLSQL 代码将 XML 文件发送到我的计算机?
- php - 找不到类“Google_Service_Docs”(Google Docs API quickstart.php)
- teradata - 在 Teradata 中结束事务后是否需要 COMMIT?