Struts2项目中配置的自定义过滤器无效

Struts2的核心过滤器不用多说,配置如下

[code="java"]

Struts2
org.apache.struts2.dispatcher.FilterDispatcher


Struts2
/*

[/code]

此外,还配置了一个自定义的过滤器,*.html (我的Struts2请求后缀是html)

结果没有进入这个过滤器,把*.html改成/*就行了,但是这个过滤器只负责拦截html,如果写/*的话所有都会拦截,比如js, css等,这样就不符合本意了,请指点。

拦截器就不用说了,我暂时不考虑用拦截器,不想因为是Struts2就放弃了原先的过滤器。

请都先看清楚了再回答,没素质的疯子远离,谢谢

我按你的意思试了试,我的过滤器配置成这样:
[code="xml"]

encoding
.action


struts2
/


some
.action

[/code]
其他部分我就忽略了,这种情况下,过滤器分别经过“encoding”、“struts2”,没有进入“some”。如果采用下面的配置:
[code="xml"]

encoding
.action


some
.action


struts2
/

[/code]
则分别经过“encoding”、“some”、“struts”。问题的关键在于过滤器中的doFilter方法中是否执行了:
[code="java"]
chain.doFilter(request, response);
[/code]
即进入到下一个过滤器。而从FilterDispatcher的实现来看,它是有可能不执行这一句的:
[code="java"]
...
if (mapping == null) {
// there is no action in this request, should we look for a static resource?
String resourcePath = RequestUtils.getServletPath(request);

            if ("".equals(resourcePath) && null != request.getPathInfo()) {
                resourcePath = request.getPathInfo();
            }

            if (staticResourceLoader.canHandle(resourcePath)) {
                staticResourceLoader.findStaticResource(resourcePath, request, response);
            } else {
                // this is a normal request, let it pass through
                chain.doFilter(request, response);
            }
            // The framework did its job here
            return;
        }

        dispatcher.serviceAction(request, response, servletContext, mapping);

...
[/code]
这里可以看出是否进入下一个过滤器是有条件的。
这就是我分析的结论,不知道是否能解答你的问题?




你在struts.xml中配置下

你的struts2版本是多少