Another way to alter a request or response is through the use of filters. A filter, as it is defined in the Java Servlet Specification v2.3, implements the javax.servlet.Filter interface. You use a filter to create a wrapper for the request and response in order to modify the data within it. You can also use a filter to examine the headers in the request and to specify the next resource to call.

A series of filters are managed by a filter chain. After a filter completes execution, it makes a call to the filter chain. The filter chain is responsible for determining the next operation: invoking another filter, halting the request execution, throwing an exception, or calling the resource that passed the request to the first filter in the chain.

The place, during the request-handling process, where a filter is invoked depends on the requested file type (JSP or JHTML).

Nucleus-based web applications use one filter, PageFilter, by default. For information on how to implement PageFilter, see Starting the Request-Handling Pipeline. You can learn about adding other filters to Nucleus-based web applications in Adding New Request-Handling Resources to web.xml.

 
loading table of contents...