在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 发布
在J2EE架构表示层,处理不同用户请求时,传统嵌套if/else语句结构缺乏扩展性。而使用J2EE Pattern中的Intercepting Filter模式可解决该问题,它能以标准方式处理通用服务,拦截请求和响应进行预处理和后处理,还能在不改动现有代码下添加或移除过滤器,此模式运用了Decorator模式。

1424

被折叠的 条评论
为什么被折叠?



