大家好,,
我在jsp页面上提取的 数据库字段有几个字是乱码,不知道是怎么回事,这些字在sql server里都没问题,就是在jsp 页面显示的时候是个 问号( 比如 李溦 显示为李?其他字都能正常显示)希望大家能给点意见.先多谢了!!!!!

解决方案 »

  1.   

    页面编码已经是GBK了,我用了一个方法:
    <%@ page import="java.io.*"%>
    <%! String trans(String chi)
    {
                   String result = "";
                   byte temp [];
                   try
                   {
                           temp=chi.getBytes("gb2312");
                          result = new String(temp);
                    }
                    catch(UnsupportedEncodingException e)
                    {
                            System.out.println (e.toString());
                    }
    return result;
    }
    %>但还是不成,,,急死我了..
      

  2.   

    你写入数据库的时候就已经是乱码了必须在入库之前的javabean里将GBK/gb2312转为ISO8859-1显示的时候由ISO8859-1转为GBK/gb2312
      

  3.   

    o ,,我的数据是从excel表里到入的呀
      

  4.   

    public class function {
    //从库中读出iso8859_1--->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;
       }
       }
    //写入库 gb2312--->iso8859_1
      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;
      }
    }要多测试几次, 总觉得没有一劳永逸地方法 :(
      

  5.   

    对了, 我的用法只在"gb2312"编码下的jsp页面用过!