开发者

Can I have a circular redirect in Grails?

开发者 https://www.devze.com 2023-02-24 03:22 出处:网络
I\'m trying to redirect circularly in Grails (no infinite redirect loop) and keep getting this error:

I'm trying to redirect circularly in Grails (no infinite redirect loop) and keep getting this error:

org.codehaus.groovy.grails.web.servlet.mvc.exceptions.CannotRedirectException: Cannot issue a redirect(..) here. 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.

//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 = {
        flas开发者_Python百科h.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')
}
0

精彩评论

暂无评论...
验证码 换一张
取 消