日期:2014-05-19 浏览次数:20824 次
HttpServletRequest request = ServletActionContext.getRequest(); request.setCharacterEncoding("gb2312"); String str = request.getParameter("msgContent"); System.out.println(str); System.out .println(new String(this.getMsgContent().getBytes(), "utf-8")); System.out .println(new String(this.getMsgContent().getBytes(), "gb2312")); System.out.println(new String(this.getMsgContent().getBytes(), "gbk")); System.out.println("可以正常么1:" + this.getMsgContent());// 1 System.out.println("可以正常么2:" + this.getMsgContent().getBytes());// 2 System.out.println("可以正常么3:" + this.getMsgContent().getBytes("GB2312"));// 3 System.out.println("可以正常么4:" + this.getMsgContent().getBytes("ISO-8859-1"));// 4 System.out.println("可以正常么5:" + new String(this.getMsgContent().getBytes()));// 5 System.out.println("可以正常么6:" + new String(this.getMsgContent().getBytes(), "GB2312"));// 6 System.out.println("可以正常么7:" + new String(this.getMsgContent().getBytes(), "ISO-8859-1"));// 7 System.out.println("可以正常么8:" + new String(this.getMsgContent().getBytes("GB2312")));// 8 System.out .println("可以正常么9:" + new String(this.getMsgContent().getBytes("GB2312"), "GB2312"));// 9 System.out.println("可以正常么10:" + new String(this.getMsgContent().getBytes("GB2312"), "ISO-8859-1"));// 10 System.out.println("可以正常么11:" + new String(this.getMsgContent().getBytes("ISO-8859-1")));// 11 System.out .println("====================================12====================="); System.out.println("可以正常么12:" + new String(this.getMsgContent().getBytes("ISO-8859-1"), "GB2312"));// 12 System.out .println("====================================13====================="); System.out.println("可以正常么1:" + new String(this.getMsgContent().getBytes("ISO-8859-1"), "ISO-8859-1"));// 13 String stra = URLDecoder.decode(this.getMsgContent(), "utf-8");// String stra1 = URLDecoder.decode(this.getMsgContent(), "gbk");// String stra2 = URLDecoder.decode(this.getMsgContent(), "gb2312");// System.out.println(stra); System.out.println(stra1); System.out.println(stra2); //运行结果如下: ????????????? ????????????? ????????????? ????????????? 可以正常么1:????????????? 可以正常么2:[B@1cf806b 可以正常么3:[B@11272ec 可以正常么4:[B@36fc18 可以正常么5:????????????? 可以正常么6:????????????? 可以正常么7:????????????? 可以正常么8:????????????? 可以正常么9:????????????? 可以正常么10:????????????? 可以正常么11:????????????? ====================================12===================== 可以正常么12:????????????? ====================================13===================== 可以正常么1:????????????? ????????????? ????????????? ?????????????