Section 5.2.2 Filtering the Request and/or Response
Once the base request or response object is obtained, it may be modified. Typically, modifications are done to achieve:
- Breaking the URI into contextPath, servletPath and pathInfo components
- Associating a resource base with a request for static content
- Associating a session with a request
- Associating a security principal with a request
- Changing the URI and paths during a request dispatch forward to another resource
The context of the request may also be updated:
- Setting of the current threads context classloader
- Setting thread locals to identify the current ServletContext
Typically, a modified request is passed to another handler. Then, the modifications are undone in the finally block afterwards:
try
{
base_request.setSession(a_session);
next_handler.handle(target, request, response,dispatch);
}
finally
{
base_request.setSession(old_session);
}
The classes that implement the HandlerWrapper class are typically handler filters of this style.


