filter & interceptor

来源:互联网 发布:tcl通讯宁波知乎 编辑:程序博客网 时间:2024/06/05 07:45

1、  filter基于回调函数,我们需要实现的filter接口中doFilter方法就是回调函数,而interceptor则基于java本身的反射机制,如果对这种形式不了解,可以去看看java是如何实现动态代理的,这是aop的基础。这是两者最本质的区别。

2、  filter是依赖于servlet容器的,即只能在servlet容器中执行,很显然没有servlet容器就无法来回调doFilter方法。而 interceptor与servlet容器无关。



任何通过Struts,或是JSF的Controller Servlet处理的request,都会在过滤器中先行处理(filter),才把控制权交还给Struts或是JSF,这时interceptor才起作用。注意这个顺序使用一种通俗的方式来讲是:filter在进入网页时选择,interceptor在提交业务过程中进行拦截,来加入需要的另外加入的业务逻辑。个人愚见

 

1) Please download the binary xxx.jar, and deploy to your JBOSS_HOME/common/lib folder. Then all web applications using jboss can share the same jar file. On live server, there will be only one copy of this jar file, making it easier for future maintenance.
 
2) In struts.xml, you need to add your own interceptor:
<interceptors>
            <interceptor name="xxx" class="com.xxx.xxx.xxx"/>
            ... ...
</interceptors>
 
You can then later using that in your interceptor stack, (replace the current cookie interceptor you have):
<interceptor-stack name="myStack">
    ...
    <interceptor-ref name="xxCookie">
        ... <!-- other config, if needed -->
    </interceptor-ref>
</intercetpro-stack>
原创粉丝点击