redirect - Controller 中操作后如何精确重定向页面(grails)

标签 redirect grails view controller

因此,我具有注销功能,我想在注销后返回登录页面。我的 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/

相关文章:

asp.net-mvc - MVC3 将@model 传递给局部 View

java - JSP/Servlet 验证 - 转发与重定向

bash - 为什么在命令替换中输入重定向的工作方式不同?

使用自定义 header 的 PHP 重定向

grails - 如何拥有更轻量级的Spring Source Tool Suite?

jsp - Grails将JSP呈现为空白页

grails - Grails是否允许使用过滤器进行声明式异常处理?

c# - 使用创建的扩展方法

view - 如何以编程方式使用另一个 View 中的按钮从 Storyboard 中打开 UIViewController?

ios - 使用 AFNetworking 2.0 拦截和防止重定向的推荐方法是什么?