我用string.getbytes(string, "ISO-8859-1")方法对一个词,比如“中国”获得一组bytearray,想分别在不同的浏览器显出来,结果在firefox显示出来的和在IE 8中显出来的bytearray的值不相同,而用new string(bytearray, "UTF-8")方法解码获得出来的词,在firefox里面正常显示成“中国”,而在IE8里面就是乱码方块,请问我哪里做错了,附带我写的编码解码的代码片段:String term = "中国";
byte[] buff = term.getBytes("ISO-8859-1");
String ss = new String (buff,"UTF-8");
byte[] buff = term.getBytes("ISO-8859-1");
String ss = new String (buff,"UTF-8");
自动检测也行
这个系统要支持多语言,所以统一用UTF-8的编码
问题是为啥火狐可以正常显示,IE不行呢
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
%><%
String userId = request.getRemoteUser();
String document_id = request.getParameter("id");
String requestLang = request.getParameter("lang");
String query_txt = (String)request.getParameter("search_str");
byte[] q2 = query_txt.getBytes("ISO-8859-1");
String q1 = new String(q2, "UTF-8");
%>
test string = <%= q1 %>
byte[] q2 = query_txt.getBytes("ISO-8859-1");
String q1 = new String(q2, "UTF-8");
是因为只有这样子才能在firefox里面正确显示中文,如果用IE则不行,但如果用
byte[] q2 = query_txt.getBytes("UTF-8");
String q1 = new String(q2, "UTF-8");
那就IE和firefox都无法正确显示,全部是乱码