【问题标题】:How exactly redirect page after action in the controller (grails)控制器中的操作后如何精确重定向页面(grails)
【发布时间】:2019-10-14 02:39:20
【问题描述】:

所以我有注销功能,我想在注销后返回登录页面。我的控制器名为 LoginController.groovy。但是注销后它只刷新页面而不是直接它。顺便说一句,它是由 spring security 插件创建的。

/**
 * 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]


}

【问题讨论】:

    标签: redirect grails view controller


    【解决方案1】:

    但注销后它只刷新页面而不是直接它。顺便说一句,它 由 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 真相的东西)时发生。

    【讨论】:

      猜你喜欢
      • 2012-10-10
      • 1970-01-01
      • 1970-01-01
      • 2015-01-03
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多