jdbc:mysql://127.0.0.1/xyz?useUnicode=true&characterEncoding=gbk
数据库连接设置一下字符集

解决方案 »

  1.   

    首先你要确定到底是那里出现乱码!
    你将向论坛添加的字符串打印出来,看看有没有乱码。
    例如:content为你提交的某一个字段名
    String str=request.getParameter("content");
    System.out.println(str);
    //看看打印的结果会不会出现乱码
    //如果出现乱码,再试试这样
    String str=new String(request.getParameter("content").getBytes("ISO-8859-1"),"UTF-8");
    System.out.println(str);
    //看看这样会不会出现乱码,如果不出现乱码就可以向数据库添加数据了//如果还出现乱码,你可以再试试这个函数有没有用
    public String codeToString(String str)
    {
       String s=str;
       try{
           byte temp[]=s.getBytes("ISO-8859-1");
           s=new String(temp);
           return s;
           }
       catch(Exception e)
       {
        return s;
       }
    }
      

  2.   

    jdbc:mysql://127.0.0.1/xxx?useUnicode=true&characterEncoding=gbk数据库:MYSQL5.0,数据库编码为gbk
    Resin编码更改为utf-8