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 ...