日期:2014-05-19  浏览次数:20578 次

struts2过滤器都做了什么
StrutsPrepareAndExecuteFilter过滤器的地址模式写成/*,会过滤所有的请求
如果请求是*.action,过滤器会映射到相应的action并执行execute
如果请求是*.jsp,那过滤器是怎么工作的

我用struts2整合了fckeditor2.6,过滤器中写成/*,fckeditor的图片上传就不能用了
过滤器的地址模式改成*.action 和*.jsp就可以用了

为什么/* 可以让*.action和*.jsp的顺利执行,fckeditor的就拦截了
------解决方案--------------------
可以自己写一个过滤器的
也就是写一个自己的类,让这个类实现于Filter这个接口,这个接口里有三个方法
init()
doFilter()
destroy()
主要是对doFilter()进行操作,你可以在这个方法里写你想进行的操作.
写完这些之后,就是在web.xml里的配置了
<filter>
    <filter-name>myFilter</filter-name>
    <filter-class>包名+实现Filter接口的类</filter-class>
</filter>
<filter-mapping>
    <filter-name>myFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

在<url-pattern>里面设置了/*之后,也就是说在进行每一个操作时都会自动去执行自定义的filter里的doFilter方法里的代码.这样就可以进行相应的过滤操作了
------解决方案--------------------
这样了还有下载 
 http://www.javaeye.com/problems/23492
------解决方案--------------------
去网上搜索。,,
------解决方案--------------------
引用:
我是想知道过滤器内部都做了哪些操作
那你只能看源码了
------解决方案--------------------
public String doIntercept(ActionInvocation invocation)
        throws Exception
    {
        Object action;
        ActionContext ac;
        Map parameters;
        Map contextMap;
        action = invocation.getAction();
        if(action instanceof NoParameters)
            break MISSING_BLOCK_LABEL_163;
        ac = invocation.getInvocationContext();
        parameters = retrieveParameters(ac);
        if(LOG.isDebugEnabled())
            LOG.debug((new StringBuilder()).append("Setting params ").append(getParameterLogMap(parameters)).toString(), new String[0]);
        if(parameters == null)
            break MISSING_BLOCK_LABEL_163;
        contextMap = ac.getContextMap();
        ReflectionContextState.setCreatingNullObjects(contextMap, true);
        ReflectionContextState.setDenyMethodExecution(contextMap, true);
        ReflectionContextState.setReportingConversionErrors(contextMap, true);
        ValueStack stack = ac.getValueStack();
        setParameters(action, stack, parameters);
        ReflectionContextState.setCreatingNullObjects(contextMap, false);
        ReflectionContextState.setDenyMethodExecution(contextMap, false);