Filters are used in web applications to perform some action on a request or response before it reaches or after it leaves the actual action handler on the server (which can be Servlet, a REST service managed by JSF Bean, etc.). Using filters, you can, for example, check whether certain requests are allowed for a registered user, and you can actually cancel the request and return the response to the client, preventing the request from reaching the actual action handler.
If you have several filters, you will have to chain them.
Interceptors act on class methods. It allows you to perform some additional processing when calling an object method without having to change the body of the method. This can be very useful if:
- you do not have access to the method body
- processing is what is repeated for a particular type of method, and you do not want to place this additional code everywhere (for example, register input parameters and output result to track execution or check security restrictions for a particular method, if you have defined some).
iullianr
source share