<%!
//转码U_to_GB
public String U_to_GB(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("GBK"),"ISO8859_1");
return str;
}public String GB_to_U(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("ISO8859_1"),"GBK");
return str;
}public String send(String s){
return s;
}
%>

解决方案 »

  1.   

    byte[] temp;
            String temps=request.getParameter("pdtname");
            temp=temps.getBytes("iso8859-1");
            String pdtname=new String(temp);
      

  2.   

    如果是MIME-encoded 或者Base64"-encoded 我应该怎么处理啊??!!
    help!!!!!
      

  3.   

    问题已经解决其实现在过程如果是这样问题解决:先getBytes("IOS8859-1","UTF-8");
    之后再转一次:getByte("ISO8859-1","GBK");
    问题解决现在还有一个问题,如果掉转来处理,我应该怎么做呢---
    我想将一个GBK的中文字段以上面处理过程的相反过程写回去,应该怎么样的顺序呢??
    我试过好多都写不成功(写当然成功,但重新读出来则又是乱码啦)----目的是希望写回去之后,我读出来的是正确的,
      

  4.   

    就是说,我如何将一个中文字段以UTF-8写处理赋值给一个变量呢??
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    不要跟我说:
    public String GB_to_U(String s) throws UnsupportedEncodingException
    {
    String str=s;
    str=new String(s.getBytes("ISO8859_1"),"UTF-8");
    return str;
    }啊。
      

  5.   

    解决办法:
    第一:
    在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;
     }
      }