O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Filters and Listeners

The servlet specification defines two component types beside servlets: filters and listeners. These compont types are also often used in a JSF-based application.

Filters

A filter is a component that can intercept a request targeted for a servlet, JSP page, or static page, as well as the response before it’s sent to the client. This makes it easy to centralize tasks that apply to all requests, such as access control, logging, and charging for the content or the services offered by the application. A filter has full access to the body and headers of the request and response, so it can also perform various transformations. One example is compressing the response body if the Accept-Encoding request header indicates that the client can handle a compressed response.

A filter can be applied to either a specific servlet or to all requests matching a URL pattern, such as URLs starting with the same path elements or having the same extension. Jason Hunter’s JavaWorld article about filters, http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-filters.html, is a good introduction to how to develop various types of filters, such as filters for measuring processing time, click and clickstreams monitoring, response compression, and file uploading.

Listeners

Listeners allow your application to react to certain events. Starting with Version 2.3 of the servlet specification, there are listener types for servlet context, session and request lifecycle events (“created” and “destroyed” ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required