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(){

}

}

原文地址:https://www.cnblogs.com/zailushang117/p/3661182.html