Servlets 未筛选web.xml错误页

Servlets 未筛选web.xml错误页,servlets,servlet-filters,custom-error-pages,Servlets,Servlet Filters,Custom Error Pages,我的应用程序正在Tomcat7上运行 我已经创建了一个url重写过滤器,它正在侦听所有传入的请求,但是,当触发错误页面时,它不会对其进行过滤,而是会过滤发生错误的页面 我在过滤器中设置了一个断点,当错误发生时,您可以在源页面上看到它触发。 但是显示的页面是/desktop/index.xhtml 这是预期的行为吗? 这是我的web.xml配置: <filter-mapping> <filter-name>UrlRewriteFilter</filter-na

我的应用程序正在Tomcat7上运行

我已经创建了一个url重写过滤器,它正在侦听所有传入的请求,但是,当触发错误页面时,它不会对其进行过滤,而是会过滤发生错误的页面

我在过滤器中设置了一个断点,当错误发生时,您可以在源页面上看到它触发。 但是显示的页面是
/desktop/index.xhtml

这是预期的行为吗?

这是我的
web.xml
配置:

<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<error-page>
    <error-code>500</error-code>
    <location>/desktop/index.xhtml?messageId=4</location>
</error-page>

URL重写过滤器
/*
500
/desktop/index.xhtml?messageId=4
这是预期的行为吗

默认情况下,过滤器仅映射到
请求
调度程序。下面

<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
请注意,您需要在此处显式指定
请求
调度程序,否则它将假定您正在完全覆盖它,并且只对
错误
调度程序感兴趣

在过滤器内部,您可以通过是否存在一个请求属性来检查它是否被触发

String errorRequestURI = (String) request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI);

if (errorRequestURI != null) {
    // Error page was triggered on the given URI.
}
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>
String errorRequestURI = (String) request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI);

if (errorRequestURI != null) {
    // Error page was triggered on the given URI.
}