服务器A 向 服务器B 传输数据,
服务器B接到数据:
两端都在方法里设置了:
request.setCharacterEncoding("UTF-8");
response.setContentType("text/plain; charset=UTF-8");
//开始获取:
String data = request.getParameter("json");
Log.info("发来数据:"+data);
String coding = getEncoding(data);
public static String getEncoding(String str) {
Log.info("--GB2312 :" + new String(str.getBytes(), "GB2312"));
Log.info("--ISO-8859-1 :" + new String(str.getBytes(), "ISO-8859-1"));
Log.info("--UTF-8 :" + new String(str.getBytes(), "UTF-8"));
Log.info("--GBK :" + new String(str.getBytes(), "GBK"));
Log.info("--GB2312 ---2:" + new String(str.getBytes("GB2312")));
Log.info("--ISO-8859-1 ---2:" + new String(str.getBytes("ISO-8859-1")));
Log.info("--UTF-8--2:" + new String(str.getBytes("UTF-8")));
Log.info("--GBK--2 :" + new String(str.getBytes("GBK")));
Log.info("UTF-8--GB2312 :" + new String(str.getBytes("UTF-8"), "GB2312"));
Log.info("UTF-8--ISO-8859-1 :" + new String(str.getBytes("UTF-8"), "ISO-8859-1"));
Log.info("UTF-8--UTF-8 :" + new String(str.getBytes("UTF-8"), "UTF-8"));
Log.info("UTF-8--GBK :" + new String(str.getBytes("UTF-8"), "GBK"));
Log.info("GB2312--UTF-8 :" + new String(str.getBytes("GB2312"), "UTF-8"));
Log.info("GB2312--ISO-8859-1 :" + new String(str.getBytes("GB2312"), "ISO-8859-1"));
Log.info("GB2312--GBK :" + new String(str.getBytes("GB2312"), "GBK"));
Log.info("GB2312--GB2312 :" + new String(str.getBytes("GB2312"), "GB2312"));
Log.info("ISO-8859-1--GBK :" + new String(str.getBytes("ISO-8859-1"), "GBK"));
Log.info("ISO-8859-1--UTF-8 :" + new String(str.getBytes("ISO-8859-1"), "UTF-8"));
Log.info("ISO-8859-1--GB2312 :" + new String(str.getBytes("ISO-8859-1"), "GB2312"));
Log.info("ISO-8859-1--ISO-8859-1 :" + new String(str.getBytes("ISO-8859-1"), "ISO-8859-1"));
Log.info("GBK--GB2312:" + new String(str.getBytes("GBK"), "GB2312"));
Log.info("GBK--ISO-8859-1:" + new String(str.getBytes("GBK"), "ISO-8859-1"));
Log.info("GBK--UTF-8:" + new String(str.getBytes("GBK"), "UTF-8"));
Log.info("GBK--GBK:" + new String(str.getBytes("GBK"), "GBK"));
}
日志截图里 xm:“???” 是中文名字,
无论怎么转换字符集,都是 ??? 格式乱码!
求大神帮忙看看!!!!