我在页面串中文参数,在本机测试都没有问题,但发布到服务器后中文参数就乱码了,请问是什么原因呢?我现在用的是 POST方式,也转码了,并且在我自己的机器上正常,服务器上就乱码,是不是需要什么设置阿 ?
String channeltypeNameList = new String(nullToBlank(request
.getParameter("channeltypeNameList")).getBytes("iso-8859-1"), "gb2312"); private String nullToBlank(String s) {
return s == null ? "" : s;
}
String channeltypeNameList = new String(nullToBlank(request
.getParameter("channeltypeNameList")).getBytes("iso-8859-1"), "gb2312"); private String nullToBlank(String s) {
return s == null ? "" : s;
}
getBytes("iso-8859-1"), "gb2312",这个会有问题。
如果转换前得到的就是iso-8859-1,这样转换没有问题。
如果转换前得到就是gb2312的,一转就出乱码了。
对服务器的设置依赖性太大。
public static String getCNString(String str)
{
try
{
str = new String(str.getBytes("iso8859-1"), "gb2312");
}
catch (Exception ex)
{
DebugTracer.except(ex);
}
finally
{
return str;
}
}在页面上将字符编码设为gb2312就ok了
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">