又是这个问题,顺便赚点分把这是最简单的中文问题了
因为数据库和app(包括页面),用的编码方式不同。
数据库的中文数据必须经过以下转换
String sApp = new String(rs.getString(1).getBytes("iso-8859-1"),"gb2312")反之
String sDB = new String(sDB.getBytes("gb2312"),"iso-8859-1")

解决方案 »

  1.   

    解决办法:
    第一:
    在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;
     }
      }
      

  2.   

    好像直接读也没什么问题吧!只要在jsp的最上边加上一句话就行了:
    <%@ page contentType="text/html; charset=GBK" %>
      

  3.   

    String sApp = new String(rs.getString(1).getBytes("iso-8859-1"),"gb2312")很好用,能解决JSP读取数据库中已经存在的中文的问题,但是String sDB = new String(sDB.getBytes("gb2312"),"iso-8859-1")
    不知道怎么使用,慢慢体会吧。