在使用response.sendredirect(url)进行重定向时,遇到中文字符,如果不做任何处理,则在后台无法得到正确的中文字符,为了解决这一问题,今天尝试了好多次方法,这里记录一下我实测通过的方法: 

使用response.sendredirect()时的处理 

String encoder = "gb2312";
String s = URLEncoder.encode("中国必胜",encoder); 
String url = Util.newPath+"/getDemandListInter.do?s="+s;
		
response.sendRedirect(url);



接收端的处理: 

String s = new String(request.getParameter("s").getBytes("iso-8859-1"));



浏览器端使用的编码风格是iso-8859-1,所以才会出现这种错误,转换一下啦~~终于搞定了,么么哒! 
ps:由于使用时的代码不在我这里,也没有做更多的尝试,使用时的代码或许可以精简也不一定,尝试ok的朋友,欢迎留言,互相学习啦~~

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-04
  • 2021-09-30
  • 2022-12-23
  • 2022-02-18
  • 2022-12-23
相关资源
相似解决方案