为什么在Grails中转发和重定向不会停止初始操作? [英] Why forward and redirect in grails don't stop initial action execution?

查看:121
本文介绍了为什么在Grails中转发和重定向不会停止初始操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了转发 redirect 在Grails中,并不理解为什么代码在下面打印foo。



请参阅:

  def bar = {
redirect(controller: public,action:index)//同样发生在forward
printlnfoo//在控制台打印这个?为什么?
}

在我看来,重定向/转发必须跳过当前的方法执行... p>

这是一个错误还是我理解这个概念错误?

解决方案

因为这些只是函数调用 - 它们不能从调用中退出功能(你的行动)。之后只需放入 return


I read about forward and redirect in Grails and don't understant why the code bellow prints "foo".

See:

def bar = {
   redirect (controller: "public", action: "index") // same happens with forward
   println "foo" // prints this in console?? WHY?
}

In my opinion redirect/forward must skip current method execution...

Is this a bug or I understand the concept wrong?

解决方案

Because these are just function calls - they can't exit from a calling function (your action). Just put return afterwards.

这篇关于为什么在Grails中转发和重定向不会停止初始操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆