Filtering Requests and Responses

A filter is an object that can transform the header and content (or both) of a request or response. Filters differ from Web components in that filters usually do not themselves create a response. Instead, a filter provides functionality that can be “attached” to any kind of Web resource. Consequently, a filter should not have any dependencies on a Web resource for which it is acting as a filter; this way it can be composed with more than one type of Web resource. The main tasks that a filter can perform are as follows:

  • Query the request and act accordingly.

  • Block the request-and-response pair from passing any further.

  • Modify the request headers and data. You do this by providing a customized version of the request. ...

Get The J2EE™ Tutorial Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.