Grails 在发生错误时重定向到页面

标签 grails redirect

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

覆盖所有错误..这可能吗?

最佳答案

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

这是 500 个响应的默认映射(来自 conf/URLMappings.groovy):

"500"(view:'/error')

这告诉应用程序渲染位于 views/error.gsp 中的 error View 。如果你想改变这一点,你可以。如果需要,您可以重定向到 Controller /操作:

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

您可以针对任何 HTTP 响应状态进行配置。请参阅URL Mappings documentation 。如果您需要更好地控制可能遇到的不同异常,请查看上面引用的文档中的“声明性错误处理”部分。

关于Grails 在发生错误时重定向到页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6191860/

相关文章:

c# - Responce.Redirect 和 Response.RedirectLocation 有什么区别?

javascript - 从 HttpContext.Response 捕获 REQUIRES_AUTH 和 xhr.status 时出现问题

wordpress - wordpress .htaccess 中的文件夹索引

date - Grails Date变量将不会设置时间

grails - Netbeans的Grails Paypal插件

authentication - Grails 通过 Spring Security 插件使用 Google 身份验证

java - java中如何重定向到外部url

grails - 在Grails Controller 类中使用静态 “hasOne”属性

grails - 如何使用grails调用域名为变量的Domain方法?

php - CakePHP 2.4 redirect() 与 POST 数据?