O'Reilly logo

Servlet & JSP: A Tutorial, Second Edition by Budi Kurniawan

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

Chapter 17

Decorating Requests and Responses

The Servlet API comes with four wrapper classes that you can use to change the behavior of servlet requests and servlet responses. The wrappers allow you to “wrap” any method in the ServletRequest and ServletResponse or their HTTP equivalents (HttpServletRequest and HttpServletReponse, respectively). These wrappers follow the Decorator or Wrapper pattern, and to utilize these wrappers you need to understand what the pattern is.

This chapter starts with an explanation of the Decorator pattern and provides an example of how to change the behavior of HttpServletRequest objects by wrapping them. The same technique can be used to wrap HttpServletResponse objects.

The Decorator Pattern

The Decorator ...

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