我正在将Resin Server和Apache 2.2与虚拟主机一起使用。
在这里,我在调用具体过滤器时面临着巨大的挑战。
我有一个通用的Filter类来处理所有传入的请求。
例如:www.example.com/hello,此呼叫未调用以下过滤器,而是抛出未找到文件错误(404)。
如果“ hello”具有正确的servlet映射,则下面的过滤器正在工作。
Web.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>
Apache日志:
[2013年1月4日星期五22:05:07] [错误] [客户端xxx.xxx.xxx.xxx]文件确实
不存在:/ home / xxxx / public_html / hello
为什么未调用servlet过滤器并抛出404错误?
Servlet过滤器正在正确初始化。
谢谢,
最佳答案
默认情况下,过滤器是在成功请求时分派的。默认情况下,它们不会在错误的请求上分派。为了也将它们分派给错误的请求,请使用适当的<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)处理。关于java - Servlet筛选器url映射/*无法处理404错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14181731/