Error pages with Servlet 3.0

懵懂的女人 提交于 2019-12-12 22:10:25

问题


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>

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>

Why doesn't the former approach work with Servlet 3.0?


I have upgraded NetBeans 7.2.1. It supports Apache Tomcat 7.0.27.0 which has Servlet 3.0 API.

By the way, I have disabled the HTTP Monitor as it raises the following warning.

MonitorFilter::WARNING: the monitor filter must be the first filter in the chain.

It happened when I used Spring security in my application and it was reported as a jira issue.


回答1:


Have a look at this post. I never personally made this

<error-page>
    <location>/WEB-INF/jsp/admin/ErrorPage.jsp</location>
</error-page>

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:

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)



来源:https://stackoverflow.com/questions/14518003/error-pages-with-servlet-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!