采用过滤器解决乱码问题:

新建类

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 *@description 中文乱码过滤器
 *@path wot.util.CharacterEncodingFilter.java
 *@copyright (c) 2012 
 *@version 1.00 Susu Jul 18, 2012 
 */
public class CharacterEncodingFilter implements Filter {
    public void destroy() {
    }
    public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("utf-8");
                        response.setCharacterEncoding("utf-8");
        chain.doFilter(request, response);
    }
    public void init(FilterConfig arg0) throws ServletException {
    }

}

修改web.xml

 <filter-name>characterEncodin</filter-name>
      <filter-class>wot.util.CharacterEncodingFilter</filter-class>
  </filter>
 
  <filter-mapping>
      <filter-name>characterEncodin</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping> 
posted on 2012-07-18 10:21  双面煎蛋  阅读(252)  评论(0编辑  收藏  举报