What is difference between Filter and Interceptor, when to use one, in which scenario ..
Definition:
A filter dynamically intercepts requests and responses to transform or use the information contained in the requests or responses. Filters typically do not themselves create responses, but instead provide universal functions that can be "attached" to any type of servlet or JSP page.
Filters can perform many different types of functions. We'll discuss examples of the italicized items in this paper:
Difference:
Definition:
A filter dynamically intercepts requests and responses to transform or use the information contained in the requests or responses. Filters typically do not themselves create responses, but instead provide universal functions that can be "attached" to any type of servlet or JSP page.
Filters can perform many different types of functions. We'll discuss examples of the italicized items in this paper:
- Authentication-Blocking requests based on user identity.
- Logging and auditing-Tracking users of a web application.
- Image conversion-Scaling maps, and so on.
- Data compression-Making downloads smaller.
- Localization-Targeting the request and response to a particular locale.
Interceptors
Interceptors are used in conjunction with Java EE managed classes to allow developers to invoke interceptor methods in conjunction with method invocations or lifecycle events on an associated target class. Common uses of interceptors are logging, auditing, or profiling.
Interceptors can be defined within a target class as an interceptor method, or in an associated class called an interceptor class. Interceptor classes contain methods that are invoked in conjunction with the methods or lifecycle events of the target class.
Introduced in JavaEE 5(relatively new concept), Interceptors are used/implemented in Struts 2 & Spring.
Introduced in JavaEE 5(relatively new concept), Interceptors are used/implemented in Struts 2 & Spring.
Difference:
A Servlet Filter is used in the web layer only, you can't use it outside of a
web context. Interceptors can be used anywhere. That's the main difference.
A.k.a. for authentication of web pages you would use a servlet filter. For
security stuff in your business layer or logging/bugtracing (a.k.a.
independent of the web layer) you would use an Interceptor.
struts2 Filter vs Interceptor
Spring's HandlerInterceptor
http://stackoverflow.com/questions/8942317/spring-interceptor-vs-servlet-filter
http://stackoverflow.com/questions/8000844/spring-handlerinterceptor-vs-filters
web context. Interceptors can be used anywhere. That's the main difference.
A.k.a. for authentication of web pages you would use a servlet filter. For
security stuff in your business layer or logging/bugtracing (a.k.a.
independent of the web layer) you would use an Interceptor.
struts2 Filter vs Interceptor
Spring's HandlerInterceptor
http://stackoverflow.com/questions/8942317/spring-interceptor-vs-servlet-filter
http://stackoverflow.com/questions/8000844/spring-handlerinterceptor-vs-filters
No comments:
Post a Comment