Servlet 3.0 的错误页面 [英] Error pages with Servlet 3.0
问题描述
在 web.xml
文件中,我试图指定一个错误页面,如下所示.
In the web.xml
file, I'm trying to specify an error page as follows.
<error-page>
<location>/WEB-INF/jsp/admin/ErrorPage.jsp</location>
</error-page>
根据 Servlet 3.0,我希望它没有错误代码,但事实并非如此.我必须明确指定适当的错误代码才能使其工作如下.
I expect it to go without an error code according to Servlet 3.0 but it doesn't. I have to explicitly specify an appropriate error code for it to work something like the following.
<error-page>
<description>Missing page</description>
<error-code>404</error-code>
<location>/WEB-INF/jsp/admin/ErrorPage.jsp</location>
</error-page>
为什么前一种方法不适用于 Servlet 3.0?
Why doesn't the former approach work with Servlet 3.0?
我已经升级了 NetBeans 7.2.1.它支持具有 Servlet 3.0 API 的 Apache Tomcat 7.0.27.0.
I have upgraded NetBeans 7.2.1. It supports Apache Tomcat 7.0.27.0 which has Servlet 3.0 API.
顺便说一下,我已经禁用了 HTTP 监视器,因为它会引发以下警告.
By the way, I have disabled the HTTP Monitor as it raises the following warning.
MonitorFilter::WARNING: 监视器过滤器必须是第一个过滤器链.
MonitorFilter::WARNING: the monitor filter must be the first filter in the chain.
当我在我的应用程序中使用 Spring security 时发生了这种情况,它被报告为 jira 问题.
It happened when I used Spring security in my application and it was reported as a jira issue.
推荐答案
看看 这篇文章.我从来没有亲自做过这个
Have a look at this post. I never personally made this
<error-page>
<location>/WEB-INF/jsp/admin/ErrorPage.jsp</location>
</error-page>
在 Tomcat 7 上工作,至于我给你的链接中描述的错误.不知道Apache在后续版本的Tomcat中是否解决了这个问题,但我对此表示怀疑.
我之前的说法可能是错误的.挖掘了一下,我发现了这个:https://issues.apache.org/bugzilla/show_bug.cgi?id=52135,这个问题应该已经在Tomcat 7.0.29解决了,所以你唯一的解决办法就是更新到post-29版本.
这里:http://tomcat.apache.org/tomcat-7.0-doc/changelog.html,在 7.0.29 版的变更日志中,您可以了解为什么会出现这样的问题:
working on Tomcat 7, as for the bug described in the link I gave you. I don't know if Apache solved it in later version of Tomcat, but I doubt.
My previous statement was probably wrong. Digging a bit, I found this: https://issues.apache.org/bugzilla/show_bug.cgi?id=52135 and the problem should have been solved in Tomcat 7.0.29, so your only solution is to update to post-29 version.
Here: http://tomcat.apache.org/tomcat-7.0-doc/changelog.html, in the changelog for version 7.0.29 you can read why there was such an issue:
添加对要在 web.xml 中定义的默认错误页面的支持仅使用嵌套的位置元素定义错误页面.它出现此功能旨在包含在 Servlet 3.0 中规范,但不小心被遗漏了.(市场)
Add support for a default error page to be defined in web.xml by defining an error page with just a nested location element. It appears this feature was intended to be included in the Servlet 3.0 specification but was accidently left out. (markt)
这篇关于Servlet 3.0 的错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!