这是别人给我回的帖子:
public class encoding{
 //中文转换
 String result="";
 public String uni2cn(String t){
  try{
   result = new String(t.getBytes("GBK"),"ISO8859_1");
  }catch(Exception e){
   result = "";
  }
   return result;
  } public String cn2uni(String t){
  try{
   result = new String(t.getBytes("ISO8859_1"),"GBK");
  }catch(Exception e){
   result = "";
  }
  return result;
 }

解决方案 »

  1.   

    在文件开头加上:
    <%@ page contentType="text/html;charset=gb2312"%> 
    <%@ page import="java.sql.*"%>
      

  2.   

    public class encoding{
     //中文转换
     String result="";
     public String str(String t){
      try{
       result = new String(t.getBytes("GBK"),"ISO8859_1");
      }catch(Exception e){
       result = "";
      }
       return result;
      } public String strrequest(String t){
      try{
       result = new String(t.getBytes("ISO8859_1"),"GBK");
      }catch(Exception e){
       result = "";
      }
      return result;
     }
      

  3.   

    在文件开头加上:
    <%@ page contentType="text/html;charset=gb2312"%> 
      

  4.   

    public class encoding{
     //中文转换
     String result="";
     public String uni2cn(String t){
      try{
       result = new String(t.getBytes("GBK"),"ISO8859_1");
      }catch(Exception e){
       result = "";
      }
       return result;
      } public String cn2uni(String t){
      try{
       result = new String(t.getBytes("ISO8859_1"),"GBK");
      }catch(Exception e){
       result = "";
      }
      return result;
     }
      

  5.   

    最简单的方法
    str=new  String(str.getBytes("8859_1"),"gb2312");  
    str=new  String(str.getBytes("gb2312"),"8859_1");  
    一前一后转换。  
      

  6.   

    在页面的前端写上<%@ page contentType="text/html;charset=gb2312"%><%
    public String getStr(String str)
    {
    byte[] bytestr = str.getBytes("ISO8859-1");
    str = new String(bytestr);
    return str
    }
    %>
      

  7.   

    中午问题有很多种,有的是页面html的文字乱码,有的是在REQUEST中传递中午的问题,还有的是从数据库中取出中午的显示问题,要具体问题,具体分析。
    一般就是编码格式的问题,通常可以打成byte看一下乱码是什么编码格式,然后转成能显示的就行了。。说了这么多 , 等于没说嘻嘻  :)
      

  8.   

    老大门,哪有这么麻烦啊
    我刚做完跟他配置完全一样
    加入数据库时charset=gb2312
    取出数据之后把数据转换一下
    new String(**.getBytes("iso8859_1"),"gb2312")
    完全就可以了啊
      

  9.   

    request.setCharacterEncoding("GBK")
    用这个也可以解决吧