我在第二页将页面设置该为
<%@ page contentType="text/html"%>后
显示的不是乱码,但到数据库中是乱码。
 
 为什么呀,快救我呀!!!谢谢谢谢谢谢谢谢谢谢谢谢!!!!!

解决方案 »

  1.   

     编译encoding  使用toChinese函数     jsp加charset=gb2312    jsp中文显示
      GB2312           1                     1                 error
                              0                     1                 ok
                              1                     0                 error
                              0                     0                 error  ISO8859_1        1                     0                 error
                                0                     0                 error
                                1                     1                 ok
                                0                     1                 error由上表看出, JSP一定要有charset=gb2312   头, 是否使用toChinese函数.取决于编译时的encoding
    选择,在中文windows里编译欠缺使用的是GB2312
    toChinese函数就是
     public static String toChinese(String strvalue)
       {
             try{
                 if(strvalue==null)
                    return null;
                 else
                 {
                    strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK");
                    return strvalue;
             }
             }catch(Exception e){
                   return null;
             }
       }
    如果程序在linux下运行,需要采取ISO8859_1    使用toChinese函数     jsp加charset=gb2312   
    办法.
      

  2.   

    我在两个页面文件中都使用了charset=gb2312,页面显示不正常,数据库中是乱码。
    如果第一个页面使用,在第二个页面中不使用charset=gb2312,则在网页显示正常,到数据库乱码。
    我是在程序头有如下代码。
    <%@ page contentType="text/html;charset=gb2312"%>