Servlet过滤器URL映射/ *不工作的404错误 [英] Servlet Filter url-mapping /* is not working on 404 errors

查看:404
本文介绍了Servlet过滤器URL映射/ *不工作的404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用树脂服务器和放大器; Apache 2.2的虚拟主机。
在这里,我面对的调用具体的过滤器的一大挑战。
我有一个通用的过滤器类来处理所有传入的请求。

I'm using Resin Server & Apache 2.2 with virtual hosting. Here I'm facing a big challenge in calling a concrete filter. I'm having a generic Filter class to process all the incoming request.

例:www.example.com/hello这个招呼并没有叫下面的过滤器,而不是将其掷文件未找到错误(404)

Ex: www.example.com/hello this hello is not calling the below filter instead it throwing file not found error(404).

如果你好是有一个合适的servlet映射,然后下面的过滤器是否正常工作。

If "hello" is having a proper servlet mapping then the below filter is working.

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日志:

[周五1月4日22时05分07秒2013] [错误] [客户xxx.xxx.xxx.xxx]文件不
  不存在:/家庭/ XXXX /的public_html /你好

[Fri Jan 04 22:05:07 2013] [error] [client xxx.xxx.xxx.xxx] File does not exist: /home/xxxx/public_html/hello

为什么Servlet过滤器不会被调用和投掷404错误?
Servlet过滤器是正确初始化。

Why the servlet filter is not being called and throwing 404 error? Servlet filter is initializing properly.

谢谢,

推荐答案

过滤器是在默认情况下成功请求调度。他们是在默认情况下不分派的是错误的请求。为了派遣他们在错误的请求,以及,用适当扩大过滤器映射&LT;分派器GT; 元素:

Filters are by default dispatched on successful requests. They are by default not dispatched on erroneous requests. In order to dispatch them on erroneous requests as well, expand the filter mapping with the appropriate <dispatcher> elements:

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

请注意,指定自定义调度类型,当你想的继续的默认请求调度员,那么你应该明确地将其指定为好。请注意,我也认为404不是由Web代理(apache httpd的)来处理,而是由servlet容器(树脂)本身,出于显而易见的原因。

Note that when specifying custom dispatcher types and you'd like to keep the default REQUEST dispatcher, then you should be explicitly specifying it as well. Note that I also assume that the 404 is not handled by the web proxy (Apache HTTPD), but by the servlet container (Resin) itself, for obvious reasons.

这篇关于Servlet过滤器URL映射/ *不工作的404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆