這樣轉化一下
String str=request.getParameter("txtName");
str=new String(str.getBytes("iso-8859-1"),"GBK");

解决方案 »

  1.   

    针对jsp和servlet:
    解决办法:
    第一:
    在jsp页面加入:
    <%@ page contentType="text/html; charset=gb2312" %>
    或者在servlet里面
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html; charset=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;
      }
      }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;
     }
      }3:)解决weblogic/webshpere中文问题:
    在web.xml文件中需要配置中文环境。r如下:
    <context-param>
      <param-name>weblogic.httpd.inputCharset./*</param-name>
      <param-value>GB2312</param-value>
    </context-param>
      

  2.   

    我也发现这种问题其它时候都很正常,只要一写进sqlserver就完了!!
      

  3.   

    zhangjianguo(笨笨) 你的方法比较有效。
    可是你知道再asp.net相关的函数怎么写吗?
      

  4.   

    String getStr(String str){
    try{
       String temp_p=str;
       byte[] temp_t=temp_p.getBytes("ISO8859-1");
       String temp=new String(temp_t);
       return temp.trim();
    }catch(Exception e)
    {
       return "null";
    }
    }
    这种情况,我总是这么处理的,希望能对你有用
      

  5.   

    这是编码的问题,数据库编码是iso-8859-1
    页面是gb2312
    页面提交会有一个过程gb2312-》iso-8859-1
    所以你要把他转成iso-8859-1——》gb2312
    数据库格式是iso-8859-1
    所以入数据的时候要gb2312-》iso-8859-1,否则是乱码
    从数据里面出来就是8859,所以必须要转化成2132才能显示。转化的方法String sApp = new String(rs.getString(1).getBytes("iso-8859-1"),"gb2312")反之
    String sDB = new String(sDB.getBytes("gb2312"),"iso-8859-1")