在J2EE架构的表示层中,需要针对不同的用户请求做一些相应的处理,有些请求可以直接传递到Controller中去,有些请求需要解码或是验证,通常的做法是写一堆嵌套的if/else语句,但是这样的结构不具有扩展性。使用J2EE Pattern中的Intercepting Filter模式就可以解决这个问题
Create pluggable filters to process common services in a standard manner without requiring changes to core request processing code. The filters intercept incoming requests and outgoing responses, allowing preprocessing and post-processing. We are able to add and remove these filters unobtrusively, without requiring changes to our existing code.
Intercepting Filter使用了GoF的Decorator模式
在Petstore中就通过两个类应用到了这个模式: EncodingFilter,SignOnFilter,他们实现javax.servlet.Filter接口
Petstore中的J2EE Pattern之Intercepting Filter
最新推荐文章于 2022-05-21 18:46:16 发布