Your First Filter : Filter « Servlet « Java Tutorial

import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet implements Filter 
  public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain)
    throws IOException, ServletException 

    System.out.println("In filter");
    chain.doFilter(request, response);
    System.out.println("Leaving filter");

  public void destroy() 

  public void init(FilterConfig filterConfig) 

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"


    <filter-name>Simple Filter</filter-name>
    <filter-name>Simple Filter</filter-name>
  Download: 88 k)

25.17.1.Your First Filter
25.17.2.Filter Response
25.17.3.Servlet Filter Init Parameter
25.17.4.Use Filter to log Configuration
25.17.5.Use Filter to check Request Parameter
25.17.6.Use Filter to Check Date
25.17.7.Simple filter for measuring servlet response times
25.17.8.Filter that uses a response wrapper to convert all output to uppercase