您的位置:首页 > 产品设计 > UI/UE

request.getParameter中文乱码问题

2014-04-12 20:36 459 查看
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(){

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: