1

我将 Resin Server & Apache 2.2 与虚拟主机一起使用。在这里,我面临调用混凝土过滤器的巨大挑战。我有一个通用的过滤器类来处理所有传入的请求。

例如:www.example.com/hello 这个 hello 没有调用下面的过滤器,而是抛出文件未找到错误(404)。

如果“hello”具有正确的 servlet 映射,则下面的过滤器正在工作。

网页.xml:

<filter>
  <filter-name>CorpFilter</filter-name>
  <filter-class>com.filter.CorpFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>CorpFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

阿帕奇日志:

[Fri Jan 04 22:05:07 2013] [error] [client xxx.xxx.xxx.xxx] 文件不存在:/home/xxxx/public_html/hello

为什么没有调用 servlet 过滤器并抛出 404 错误?Servlet 过滤器正在正确初始化。

谢谢,

4

1 回答 1

3

默认情况下,过滤器在成功的请求上分派。默认情况下,它们不会在错误请求上分派。为了在错误请求上也分派它们,请使用适当的<dispatcher>元素扩展过滤器映射:

<filter-mapping>
    <filter-name>CorpFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>

请注意,当指定自定义调度程序类型并且您希望保留默认REQUEST调度程序时,您也应该明确指定它。请注意,出于显而易见的原因,我还假设 404 不是由 Web 代理 (Apache HTTPD) 处理,而是由 servlet 容器 (Resin) 本身处理。

于 2013-01-07T17:43:57.633 回答