jsp页面加上<%@ page contentType="text/html; charset=gb2312" %>
在获得变量值之前加上
request.setCharacterEncoding("gb2312");
这点小问题,不要烦嘛

解决方案 »

  1.   


    public String getStr(String str)throws Exception{
        try{
          String tmp_p = new String(str);
          String temp=new String(tmp_p.getBytes("ISO8859_1"));
          return temp;
        }catch(Exception e){
          throw e;
        }
       return  "null";
      }
      

  2.   

    乱码问题是jsp程序中最常见的一个问题,一般而言是需要转码的,有些时候,写数据库需要转码取的时候也需要转码,有的时候,写的时候要转,取的时候却不用转,所以我的做法是用一个配置文件来控制时否需要转码,转码的函数可以这样写:
    public static String webtoDB(String source){
        if(source==null) return null;
        
        if(needConvert)  //如果需要转码(从配置文件中取needConvert的设置)
           return new String(source.getBytes("ISO8859-1"));
        else //不需要转码直接返回
           return source;
        //如果需要转两次可以这样
        //return new String(source.getBytes("ISO8859-1"),"GBK");
    }
    至于dbtoweb则是反向的。
    而编码方式则需要自己去试验了,每一种操作系统,每一种应用服务器可能都有所不同。我这里只是随便举一个例子
      

  3.   

    <%@ page contentType="text/html; charset=gb2312" %>
    request.setCharacterEncoding("gb2312");
      

  4.   

    强烈支持   aku0708(阿酷)
      

  5.   

    乱码的情况比较复杂,不同情况不同对待,不过我们现在开发用mysql+resin+jbuilder,全部都配置成iso8859-1,不用转码。
    <%@ page contentType="text/html; charset=ISO8859_1" %>
    以前用weblogic+oracle好像作了转换。
      

  6.   

    public String getStr(String str)throws Exception{
        try{
          String tmp_p = new String(str);
          String temp=new String(tmp_p.getBytes("ISO8859_1"));
          return temp;
        }catch(Exception e){
          throw e;
        }
       return  "null";
      }