日期:2014-05-18  浏览次数:20684 次

奇怪的乱码问题
System.out.println("1:"+msg);
System.out.println("2:"+new String(msg.getBytes()));
System.out.println("31:"+new String(msg.getBytes(),"GBK"));
System.out.println("32:"+new String(msg.getBytes(),"GB2312"));
System.out.println("4:"+new String(msg.getBytes(),"UTF8"));
System.out.println("5:"+new String(msg.getBytes(),"ISO-8859-1"));
System.out.println("6:"+new String(msg.getBytes("GB2312")));
System.out.println("7:"+new String(msg.getBytes("GB2312"),"utf8"));
System.out.println("8:"+new String(msg.getBytes("GB2312"),"GBK"));
System.out.println("9:"+new String(msg.getBytes("GB2312"),"ISO-8859-1"));
System.out.println("10:"+new String(msg.getBytes("ISO-8859-1")));
System.out.println("11:"+new String(msg.getBytes("ISO-8859-1"),"GB2312"));
System.out.println("12:"+new String(msg.getBytes("iso-8859-1"),"gbk"));
System.out.println("13:"+new String(msg.getBytes("iso-8859-1"),"utf8"));
System.out.println("14:"+new String(msg.getBytes("utf-8")));
System.out.println("15:"+new String(msg.getBytes("UTF-8"),"GBK"));
System.out.println("16:"+new String(msg.getBytes("utf-8"),"gb2312"));
System.out.println("17:"+new String(msg.getBytes("UTF-8"),"ISO-8859-1"));
System.out.println("18:"+new String(msg.getBytes("GBK")));
System.out.println("19:"+new String(msg.getBytes("GBK"),"utf8"));
System.out.println("20:"+new String(msg.getBytes("GBK"),"GB2312"));
System.out.println("21:"+new String(msg.getBytes("GBK"),"ISO-8859-1"));

---==

1:?? ??? ???????
2:?? ??? ???????
31:?? ??? ???????
32:?? ??? ???????
4:?? ??? ???????
5:?? ??? ???????
6:?? ??? ???????
7:?? ??? ???????
8:?? ??? ???????
9:?? ??? ???????
10:?? ??? ???????
11:?? ??? ???????
12:?? ??? ???????
13:?? ??? ???????
14:锟斤拷 锟斤拷锟? 说锟斤拷????
15:锟斤拷 锟斤拷锟? 说锟斤拷????
16:锟斤拷 锟斤拷锟? 说锟斤拷????
17:?????? ????????? ????????????
18:?? ??? ???????
19:?? ??? ???????
20:?? ??? ???????
21:?? ??? ???????

------解决方案--------------------
你的msg输出的时候都是乱码了,好好检查下吧
------解决方案--------------------
乱码的原因很多的,可能在传输前也可能在你输出时
举个例子吧:
假如你在jsp中这样做pageEncoding="ISO-8859-1",那么你的浏览器会以ISO-8859-1方式解码,如果你传过来的是GBK编码的数据时,自然要出现乱码.如果你不指定,浏览器会自己根据你的系统本地信息自动为你选默认编码方式来解码(一般简体中文的操作系统默认编码是gb18030,繁体中文可能就是Big5了).当然造成乱码的原因很多,这只是举个最简单的例子,我不知道你的具体原因,所以爱莫能助