|
NOTE:
These slides have not been updated since 2003. They have been superseded by the book
Anders Møller and Michael Schwartzbach, February 2006 |
|
| INTERACTIVE WEB SERVICES WITH JAVA |
|
A Filter can modify
FilterChain: multiple filters are processed in deployment order in a stack discipline with the Servlet in the bottom.
Supplementary, HttpServletRequestWrapper and HttpServletResponseWrapper provide wrappers to modify the request/response.
Example filter and deployment declaration:
public class TraceFilter implements Filter
{
private ServletContext context;
public void init(FilterConfig config)
throws ServletException
{
context = config.getServletContext();
}
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws IOException, ServletException
{
context.log("["+request.getRemoteHost()+"] request: "+
((HttpServletRequest) request).getRequestURL());
chain.doFilter(request, response);
context.log("["+request.getRemoteHost()+"] done");
}
}
|
<filter> <filter-name>myfilter</filter-name> <filter-class>TraceFilter</filter-class> </filter> <filter-mapping> <filter-name>myfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> |
|
| COPYRIGHT © 2002-2003 ANDERS MØLLER & MICHAEL I. SCHWARTZBACH |
|