Servlet Filter


Servlet Filter

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.

  • Filter is pluggable
  • Filter can intercept HTTP request
  • Filter work before and after execution of filtering data
  • It's entry is defined in web.xml file. so we can remove filter entry form web.xml filter will be removed automatically, we don't have to change 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.

filter