[ Team LiB ] Previous Section Next Section

Hour 7. Servlet Filters

What You'll Learn in This Hour:

  • What the basic methods of a Filter are

  • How to configure a filter into a container

  • How to write a simple Filter

Although JSPs and servlets are fairly powerful, there are times when you need to augment their capabilities. For example, you may want to compress the output of a JSP or servlet if the browser supports compression. Or you may be interested in encrypting or filtering content.

Servlet filters enable you to intercept incoming requests, possibly modifying the request parameters before invoking other filters or the desired JSP or servlet. After the JSP or servlet executes, the filter can modify the response parameters before returning the response to the browser. Filters can also modify headers.

In addition to all of the capabilities mentioned above, filters can be applied collectively to resources, making them a versatile instrument for factoring out function ality that may be reusable. Filters can also be used to extend the capabilities of a request or response object by using the Decorator pattern.

    [ Team LiB ] Previous Section Next Section