[ Team LiB ] Previous Section Next Section

Summary

Filters are very powerful. They can manipulate requests prior to being handled by servlets or JSPs or perform post-processing on a response before returning it to a client. This makes them ideal for content filtering, authentication, and data manipulation. Implementing a filter is often as simple as writing methods to initialize and deconstruct a filter, and writing the doFilter method, which does most of the work.

Filters also give you flexibility of design. Functionality that is common to many application resources can be factored out, making it possible to build cleaner, more maintainable Web applications. TimingFilter and SessionRecorder are examples of how logging can be performed for many resources using only a single filter.

You may also decide to use filters to remove code that might ordinarily be part of a JavaServer Page—so that you have improved separation between business logic and presentation. And you can extend objects to provide more specialized interfaces, such as presenting a DOM interface to a servlet that expects XML documents.

    [ Team LiB ] Previous Section Next Section