response.sendRedirect传中文参数的问题

http://blog.chinaunix.net/uid-7431665-id-2627263.html
http://bbs.csdn.net/topics/320245988
 
   前几天在处理用 response.sendRedirect跳转页面传参数的过程发现,如果参数中有中文的话!如果不在传输前处理的话,在接收页面中文参数则取不到!
   需要经过处理
例子:
  传递页面: chuandi.jsp
  接收页面: jieshou.jsp
 
  String temp = "中文参数"
  temp= java.net.URLEncoder.encode(temp.toString(),"gb2312"); 
  response.sendRedirect("jieshou.jsp?temp="+temp);
 
 这样处理后 则在 jieshou.jsp 页面可以通过 requst.getParamter("temp");取到中文参数
 
 
一方面sendRedirect的请求中,?子句必须手动进行URLEncoding。如:

String message = URLEncoder.encode("输入成功", "UTF-8");
response.sendRedirect("A.jsp?message=" + message);

另一方面,A.jsp接收到的message需要进行一定的处理。如

<%
  String tmp = request.getParameter("name");
  tmp = new String(tmp.getBytes("ISO-8859-1"), "UTF-8");
%>
<%=tmp%>
 
更多解释参看上一篇 中文乱码的转载文章
posted @ 2016-09-26 18:30  liness0713  阅读(1464)  评论(0)    收藏  举报