因此,我具有注销功能,我想在注销后返回登录页面。我的 Controller 名为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]
}
最佳答案
But after logout it only refresh the page and not direct it. Btw, it created by spring security plugin.
你有这个:
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真实性的东西)时,重定向才会发生。
关于redirect - Controller 中操作后如何精确重定向页面(grails),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58369447/