简体   繁体   English

我可以在Grails中进行循环重定向吗?

[英]Can I have a circular redirect in Grails?

I'm trying to redirect circularly in Grails (no infinite redirect loop) and keep getting this error: 我正在尝试在Grails中循环重定向(无无限重定向循环),并不断收到此错误:

org.codehaus.groovy.grails.web.servlet.mvc.exceptions.CannotRedirectException: Cannot issue a redirect(..) here. org.codehaus.groovy.grails.web.servlet.mvc.exceptions.CannotRedirectException:无法在此处发出redirect(..)。 The response has already been committed either by another redirect or by directly writing to the response. 响应已经通过另一个重定向或直接写入响应来提交。

I am trying to do something like this where I redirect to another action on the controller then redirect back. 我试图做这样的事情,我重定向到控制器上的另一个动作,然后重定向回去。 Wondering why Grails is not allowing this. 想知道为什么Grails不允许这样做。

//initial action and final redirect location
def showStuff = {
        if (flash.neatStuff){
             return render("found neat stuff")
        } else if (params.email) {
            return redirect(action:'getNeatStuff',params:[email:params.email, emailOnly:true])
        }
        return render("Unable to find stuff, use param")
    }

def getNeatStuff = {
        flash.neatStuff = new Date()
        if (params.emailOnly){
              redirect(action:'showStuff')
        }
        redirect(action:'someOtherPlace')
}

Ok, I had a total brain fart. 好吧,我全脑都放屁了。 I corrected the code below in case anyone runs into this same error. 我更正了以下代码,以防有人遇到相同的错误。 I was racking my brain looking at other things, but I just wasn't returning the redirect on the action. 我当时全神贯注地看着其他事情,但我只是没有返回该操作的重定向。

def getNeatStuff = {
        flash.neatStuff = new Date()
        if (params.emailOnly){
              return redirect(action:'showStuff')
        }
        redirect(action:'someOtherPlace')
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM