String abc = new String(aa.getBytes("ISO-8859-1"),"GB2312");试试看!中文的编码我有点忘了!可能是这样的!

解决方案 »

  1.   

    编译所有的servlet都加参数,
    用命令javac testServlet.java -encoding 8859_1在servlet中的中文转码,用new String(s.getBytes("8859_1"),"gb2312")当然,还要设置头信息
    response.setContentType("text/html;charset=gb2312");
      

  2.   

    楼上的对!这是servlet从页面上取字时编码在搞鬼吧?
      

  3.   

    同意楼上,不外乎是这两种转换:
    String temp=new String(temp_p.getBytes("ISO8859-1"),"GB2312");
    String temp=new String(temp_p.getBytes("GB2312"),"ISO8859-1");
      

  4.   

    3:)针对jsp和servlet:
    解决办法:
    第一:
    在jsp页面加入:
    <%@ page contentType="text/html; charset=gb2312" %>
    或者在servlet里面
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html; charset=gb2312");//这是重要的
    上面的如果在不行就用如下的方法在数据入库前进行调用:
    public static String UnicodeToChinese(String s){
      try{
         if(s==null||s.equals("")) return "";
         String newstring=null;
         newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
         return newstring;
        }
      catch(UnsupportedEncodingException e)
      {
      return s;
      }
      }public static String ChineseToUnicode(String s){
      try{
      if(s==null||s.equals("")) return "";
      String newstring=null;
      newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
       return newstring;
      }
      catch(UnsupportedEncodingException e)
      {
      return s;
     }
      }