doFilter没有被调用 [英] doFilter not getting called

查看:114
本文介绍了doFilter没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能帮忙检查为什么doFilter没有被调用

Could you help to check why doFilter not getting called

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<filter>
<filter-name>roseFilter</filter-name>
<filter-class>net.paoding.rose.RoseFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>roseFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
</web-app>

班级签名:

import org.springframework.web.filter.GenericFilterBean;
public class RoseFilter extends GenericFilterBean {

在调用 http:// localhost:8080 / hello / world ,我将断点设置在
doFilter,似乎doFilter没有被调用? (我试过tomcat 6.0.18,6.0.29,jdk1.6)

404 is returned while call http://localhost:8080/hello/world, I set the breakpoints at doFilter, it seems doFilter not called?(I tried tomcat 6.0.18, 6.0.29, jdk1.6)

推荐答案

在以下情况下不会调用过滤器:

The filter won't be invoked when:


  1. 类路径中缺少过滤器类和/或不可加载或可实例化。但是,您应该在服务器的启动日志中注意到它。可以根据服务器日志中发现的异常/错误的解释找到解决方案。

  1. The filter class is missing in the classpath and/or is not loadable or instantiable. You should however have noticed it in the server's startup logs. Solution is to be found based on the interpretation of the exceptions/errors found in the server logs.

在链中运行的另一个过滤器不是调用 FilterChain #doFilter() ,而是 RequestDispatcher#forward() include() 导致链中的后续过滤器被完全跳过(当他们不听 FORWARD时 INCLUDE 调度员;它们默认只侦听 REQUEST 调度程序)。解决方法是修复错误的过滤器,或者相应地添加< dispatcher> FORWARD< / dispatcher> 等,或重新排列中的过滤器声明web.xml 以便您的新过滤器之前另一个过滤器(您只需要确保您的新过滤器使用 FilterChain# doFilter()正确:))。

There's another filter running before in the chain which isn't calling FilterChain#doFilter(), but rather RequestDispatcher#forward() or include() which caused the subsequent filters in the chain being completely skipped (when they do not listen on FORWARD or INCLUDE dispatchers; they by default only listens on REQUEST dispatcher). Solution is either to fix the wrong filter, or to add <dispatcher>FORWARD</dispatcher> etc accordingly, or to rearrange the filter declarations in web.xml so that your new filter comes before the another filter (you in turn only need to ensure that your new filter is using the FilterChain#doFilter() properly :) ).

请求URL是完全错误的。您使用了 http:// localhost:8080 / hello / world 。使用过滤器侦听 / * ,这意味着webapp上下文应为ROOT或至少 / hello 。验证您的webapp上下文。我只是使用一个URL重试,该URL指向同一webapp中的有效JSP / Servlet,它生成非404响应。那么过滤器也会被调用吗?

The request URL is plain wrong. You used http://localhost:8080/hello/world. With a filter listening on /*, this means that the webapp context should be ROOT or at least /hello. Verify your webapp context. I'd just retry with an URL which points to a valid JSP/Servlet inside the same webapp which generates a non-404 response. Does the filter then get called as well?

这篇关于doFilter没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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