0

This question was asked in an answer Difference between Interceptors and Filters - Is this right?, but it remained unanswered.

Can anyone please provide some real time examples on this?
As we can use both Filter and Interceptor for Pre-processing and Post-processing of a request.

What would be the use cases(scenarios) where servlet filter is used outside of Struts2 but within the same web application?

Community
  • 1
  • 1
Rohit Gaikwad
  • 3,677
  • 3
  • 17
  • 40
  • What servlet filter? – Roman C Nov 25 '16 at 21:39
  • @RomanC, As we can use both filter and interceptor for (pre/post) processing http request. What are the specific use cases in which only servlet filter (javax.servlet.Filter) would be used instead of interceptor and vice versa. If Filter can do such things then what was the need to invent interceptors. I think interceptors were designed to intercept requests that bypass through Struts framework(). – Rohit Gaikwad Nov 27 '16 at 06:16
  • 1
    This is not true, interceptors were designed to intercept an action, and change the way before it's executed. – Roman C Nov 27 '16 at 11:28

1 Answers1

1

I had some issues combining Apache Shiro (a login framework) with a Struts2 webapp. Because Struts2 was handling the actions of the login (ie using s: tags), a lot of default stuff on Shiro broke such as built-in email validations, remember me and so on.

This also caused Struts2 validation to stop working on Shiro pages (login and createuser) along with JDBC connection problems as I had Struts2 performing actions on sessionfactories built from hibernate.cfg.xml ORM configs, and non ORM connections in Shiro.ini.

In combination with other frameworks, sometimes you don't want Struts2 to handle the actions, as you will have certain issues like I described above. I'm sure there are other examples but this was something I experienced. I lost a lot of built in features provided by Apache Shiro because I had struts handling the actions.

Noel Murphy
  • 1,264
  • 1
  • 8
  • 12