new String( string.getBytes("iso-8859-1"), "GB2312") 
我知道 string.getBytes("iso-8859-1")是为了得到原来的字节串,但new String( string.getBytes("iso-8859-1"), "GB2312") 之后我认为应该是得到ANSI编码的字符串,但为什么是Unicode字符串呢?

解决方案 »

  1.   

    由于Java默认的编码方式是UNICODE,所以用中文易出问题,常用解决:
    String s2 = new String(s1.getBytes(“ISO-8859-1”),”GBK”);utf-8解决JSP中文乱码问题,在页面的开始处加:
    <%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <%request.setCharacterEncoding("UTF-8");%>如果仍不能解决问题,还需要这样处理一下:
    String msg = request.getParameter("message");
    String str=new String(msg.getBytes("ISO-8859-1"),"UTF-8");out.println(st); 
      

  2.   

    首先感谢你的回答。你的意思是不是说String s2 = new String(s1.getBytes(“ISO-8859-1”),”GBK”); 之后仍得到的是ANSI字符串,只不过是在<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <%request.setCharacterEncoding("UTF-8");%> 里去处理这种ANSI字符?