Filters are a feature that was introduced in version 2.3 of the servlet specification. A filter is a special type of servlet that dynamically intercepts requests and responses and transforms the information contained in them. The main advantage of filters is that they can be added to existing applications without any need for recompilation.
Filters can have several important uses:
To encapsulate recurring tasks in reusable units
To format the data sent back to the client
To provide authorization and blocking of requests
To provide logging and auditing
A filter can perform filtering tasks on the request, the response, or both.
A filter is a servlet that also implements the javax.servlet.Filter interface.