有没有办法配置使用一个自定义错误页面的所有错误代码在tomcat的web.xml中? [英] Is there a way to configure usage of ONE custom error page for ALL error codes in tomcat's web.xml?

查看:210
本文介绍了有没有办法配置使用一个自定义错误页面的所有错误代码在tomcat的web.xml中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题中所述,我想更改tomcat中的默认错误页面并执行了以下操作:

As said in the in the title, I want to change default error pages in tomcat and did:

<error-page>
  <error-code>500</error-code>
  <location>/error_500.html</location>
</error-page>

 <error-page>
   <error-code>404</error-code>
   <location>/error_404.html</location>
</error-page>

是否可以使用通配符错误代码,例如

Is it possible to use wildcard error codes like

<error-page>
  <error-code>*</error-code>
  <location>/error.html</location>
</error-page>

感谢

推荐答案

p>否,在Tomcat中没有办法。

No, there is no way in Tomcat.

Servlet 3.0规范支持一个全局错误页面,如下所示:

The Servlet 3.0 specification supports a global error page as follows:

<error-page>
    <location>/error.html</location>
</error-page>

所以在理论上它应该至少在Tomcat 7.0中工作。但它没有在Tomcat 7.0中正确实现。我曾经报告过问题52135 ,但他们拒绝了。它可以工作在其他Servlet 3.0容器虽然。

So in theory it should work in at least Tomcat 7.0. But it's not properly implemented in Tomcat 7.0. I have ever reported issue 52135 about this, but they denied it. It works on other Servlet 3.0 containers though.

但你可以解决这个问题,通过实现一个Tomcat特定 ErrorReportValve 类,然后注册为<Host errorReportValveClass>

You can however workaround this by implementing a Tomcat-specific ErrorReportValve class which you then register as <Host errorReportValveClass>.

这篇关于有没有办法配置使用一个自定义错误页面的所有错误代码在tomcat的web.xml中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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