出现错误时,Grails会重定向到页面 [英] Grails redirect to a page in case of error

查看:148
本文介绍了出现错误时,Grails会重定向到页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的问题。有没有可能,如果在任何情况下应用程序中有错误,并且服务器向我们显示错误页面,而是将所有内容重定向到默认页面?

Here is a simple question. Is there any possibility of, if in any case there's an error in an application and the server show us an error page, instead redirect everything to a default page ?

覆盖全部错误..这是可能的吗?

Covering all errors.. is that possible ?

推荐答案

Grails已经为您做到了这一点。如果异常冒泡到容器,它将作为HTTP 500(内部服务器错误)进行处理。使用 conf / URLMappings.groovy ,您可以控制发生错误状态时发生的情况。

Grails already does this for you. If an exception bubbles up to the container, it gets handled as an HTTP 500 (Internal Server Error). With conf/URLMappings.groovy you can control what happens what happens when error statuses occur.

以下是默认映射对于500个响应(来自 conf / URLMappings.groovy ):

Here's the default mapping for 500 responses (from conf/URLMappings.groovy):

"500"(view:'/error')

这告诉应用程序呈现 error view,它位于 views / error.gsp 中。如果你想改变这一点,你可以。如果你想要的话,你可以重定向到一个控制器/动作:

This tells the application to render the error view, which is located in views/error.gsp. If you want to change this, you can. You could redirect to a controller/action if you want:

// will go to 'custom' action of ErrorController, which you would create yourself
"500"(controller: "error", action: "custom")

您可以将其配置为任何HTTP响应状态。请参阅 URL映射文档。如果您需要更好地控制可能遇到的不同异常,请参阅上述参考文档中的声明性错误处理部分。

You can configure this for any HTTP response status. See the URL Mappings documentation. If you need finer control over different exceptions that might be encountered, look at the "Declarative Error Handling" section in the referenced docs above.

这篇关于出现错误时,Grails会重定向到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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