request.getParameter中文乱码问题

1、获取URL的值为乱码(GET)

String para=new String(request.getParameter("para").getBytyes("iso8859-1"),"gb2312");

2、获取Form的值为乱码(POST)

使用过滤器

配置EncodingFilter;

public class EncodingFilter Implements Filter{

public void init(FilterConfig fconfig)throws ServletException{

}

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws Exception{

  request.setCharacterEncoding("utf-8");//根据你的页面设置

  System.out.println("------------Change Encoding OK!----------");

     chain.doFilter(request,response);

}

public void destroy(){

}

}

posted on 2014-04-12 20:36  那些年我们一起奋斗的日子  阅读(1712)  评论(0编辑  收藏  举报