问题描述
正如标题中所说,我想更改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>
?
(上面的例子不起作用,但还有其他方法吗?)
(The example above doesn't work, but is there another way?)
谢谢
推荐答案
不,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 中正确实现.我曾经报告过issue 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
类,然后您将其注册为 <主机错误ReportValveClass>
.
You can however workaround this by implementing a Tomcat-specific ErrorReportValve
class which you then register as <Host errorReportValveClass>
.
这篇关于有没有办法为tomcat的web.xml中的所有错误代码配置一个自定义错误页面的使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!