Filter

  • A filter dynamically intercepts requests and responses to transform or use the information contained in the requests or responses but typically do not themselves create responses.
  • Filters improve reusability by placing recurring tasks in the filter as a reusable unit.
  • The filters can be used for
    • caching and compressing content,
    • logging and auditing,
    • image conversions (scaling up or down etc),
    • authenticating incoming requests,
    • XSL transformation of XML content,
    • localization of the request and the response,
    • site hit count etc.
  • The filters are configured through the web.xml file as follows:
HitCounterFilter myPkg.HitCounterFilter HitCounterFilter /usersection/* ...
  • Servlet filters use the slightly modified version of the chain of responsibility design pattern.