【发布时间】:2016-04-01 09:42:58
【问题描述】:
我在我的项目中使用 Grails 2.3.11。
我有下一个情况:
我有控制器,在异常时调用重定向:
class SomeController{
someAction(){
try {
doSmth()
} catch (exception) {
return redirect (action: 'index') //first redirect HERE
}
}
}
我有过滤器,它也会在另一个异常上调用重定向。
class BreadCrumbsFilters {
def filters = {
all(
controller: '*',
action: '*'
) {
after = {
if (request.xhr) return
try {
buildBreadCrumbs()
} catch (IllegalArgumentException) {
redirect(controller: 'login', action: 'auth') //second redirect HERE
return false
}
}
}
}
}
重定向不能被调用两次。
问题:如何检查是否已经调用了重定向?
我找到了下一个解决方案: 检查响应状态。
if(response.status != 3**) redirect();
这个方法正确吗? 谢谢!
【问题讨论】:
标签: spring http redirect grails