关于中文乱码

来源:互联网 发布:java web 2年水平 编辑:程序博客网 时间:2024/06/06 09:26
解决post:request.setCharacterEncoding("urf-8");
解决get:在server.xml中加URIEncoding="UTF-8"

Browser--------------->>>>>>>>>>>>[ISO8859-1]>>>>>>>>>>>>>>>--------------------->Server
String s = "中文";
中文乱码的万能解决方式
先解码: 将乱的数据再次还原为最初的字节数组 byte[] bytes = s.getBytes("ISO8859-1");
再编码:使用一种支持中文的编码方式进行重新编码 String ss = new String(bytes,"UTF-8");

Server--------------->>>>>>>>>>>>[ISO8859-1]>>>>>>>>>>>>>>>--------------------->Browser
String s = "操作日志";
先解码:byte[] bytes =  s.getBytes("UTF-8");
再编码:String ss = new String(bytes,"ISO8859-1");
new String(s.getBytes("UTF-8"),"ISO8859-1");
0 0
原创粉丝点击