Liny_@NotePad

沉迷ACG中

Response.sendRedirect 中文传参乱码

YOYO posted @ 2010年3月26日 08:03 in 【Java EE】 with tags 中文 , 3606 阅读

实验在sendRedirect之前用response.setCharacterEncoding("GBK")无效

原因:sendRedirect里面的URL传参是通过GET方法,会被强行转换成ISO-8859-1来传输(如果使用tomcat的话。修改tomcat默认编码请见:http://yoyo.is-programmer.com/posts/10306.html

解决方案:传参时通过java.net.URLEncoder.encode方法进行编码,或在收到参数时以new String(arg.getBytes("ISO-8859-1"), "GBK")方式转码。


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter