A filter is an object that is invoked at the preprocessing and postprocessing of a request.
It is mainly used to perform filtering tasks such as conversion, logging, compression, encryption
and decryption, input validation etc.
The servlet filter is pluggable, i.e. its entry is defined in the web.xml file, if we remove the
entry of filter from the web.xml file, filter will be removed automatically and we don't need to
change the servlet.
Usage of servlet filter:
- Authentication and authorization.
- Formating of the request before sending the request.
- compress the response data.
- Alter response by adding some cookies, sesion, etc.
- input validation.