开发者

Will it be a good practice to extend the Struts Framework's FilterDispatcher?

开发者 https://www.devze.com 2023-03-08 21:36 出处:网络
I am trying to use Hibernate with Struts. Will it be a good pratice if I extend the FilterDispac开发者_如何学Pythonther for calling Hibernate Utility classes?

I am trying to use Hibernate with Struts. Will it be a good pratice if I extend the FilterDispac开发者_如何学Pythonther for calling Hibernate Utility classes?

Anyone have any views? I want to discuss the pros and cons with this approach.


Don't extend FilterDispatcher.

As duffymo indicated, if you need to set up and tear down a Hibernate session for the current request, you should use an interceptor. You can use the OpenSessionInViewInterceptor that he linked too, or if you don't use Spring, you can create your own.


It sounds to me like you want to have functionality similar to Spring's OpenSessionInViewInterceptor. If yes, the fact that another framework has already done such a thing suggests that it is a good practice.


The point is usually you don't want to map a filter to all your requests - For example you don't need a transaction for some pages - The api doc for FilterDispatcher says that

IMPORTANT: this filter must be mapped to all requests. Unless you know exactly what you are doing, always map to this URL pattern: /*

So FilterDispatcher is all or nothing. Which tells a old good Filter is a better choice for open session in view pattern.

0

精彩评论

暂无评论...
验证码 换一张
取 消