比如说一个中文转化的问题,总是要在servlet(jsp)里面处理request里面的encoding,这样你就可以放在一个filter里package mytest;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;public class GBKEncoding
    implements Filter {
  private FilterConfig filterConfig;
  //Handle the passed-in FilterConfig
  private static boolean debug = true;
  public void init(FilterConfig filterConfig) {
    this.filterConfig = filterConfig;
  }
  public void setFilterConfig( FilterConfig filterConfig )
  {
    this.filterConfig = filterConfig;
  }
  public FilterConfig getFilterConfig()
  {
    return this.filterConfig;
  }
  public void doBeforeProcessing(ServletRequest request,
                                 ServletResponse response) throws IOException,
      ServletException {
    if (debug)
      System.out.println("GBKEncoding:DoBeforeProcessing");
    request.setCharacterEncoding("GBK");
  }  private void doAfterProcessing(ServletRequest request,
                                 ServletResponse response) throws IOException,
      ServletException {
    if (debug)
      System.out.println("GBKEncoding:DoAfterProcessing");
  }  //Process the request/response pair
  public void doFilter(ServletRequest request, ServletResponse response,
                       FilterChain filterChain) throws IOException,
      ServletException {
    if (debug)
      System.out.println("GBKEncoding:doFilter()");
    doBeforeProcessing(request, response);
    Throwable problem = null;
    try {
      filterChain.doFilter(request, response);
    }
    catch (Throwable t) {
      problem = t;
      t.printStackTrace();
    }
    doAfterProcessing(request, response);    if (problem != null) {
      if (problem instanceof ServletException) {
        throw (ServletException) problem;
      }
      else if (problem instanceof IOException) {
        throw (IOException) problem;
      }
      else {
        throw new ServletException(problem);
      }
    }  }  //Clean up resources
  public void destroy() {
  }
}