讨论:JSP 通过URL传递汉字,为奇数个,最后一个为乱码?为偶数个,则正常显示?
寻求最佳解决方案!!

解决方案 »

  1.   

    最佳解决方案应该就是编码encodeURI编码,decodeURI解码吧,搜搜看
     
      

  2.   

    我也遇到过这个问题,试了很多方法都不行,
    目前办法是把汉字字符编码再传送,暂时解决了。
    encodeURIComponent("汉字")
      

  3.   

    用URLEncoder.encode方法把汉字参数重新编码
    例如:
    String url = "http://localhost:90/test/login.do?id=" + onlineMd.getId() + "&org=" + java.net.URLEncoder.encode(onlineMd.getOrg(), "utf-8");
      

  4.   

    最佳解决方案,就是不用url传值,就用隐藏表单域和 放在作用域中
      

  5.   

    添加过滤器了吗?加过滤器,编码统一 utf-8 一般不会出问题URL传参虽然方便,但不安全也不稳定...建议放在作用域中.
      

  6.   

    直接传汉字是不可能完成的任务。因为url编码也可以在客户端设置的,所以最好别用。
      

  7.   

    楼主把你传送的内容贴上吧,蹊跷的现象。
    后台接受数据的地方使用编码转换:例如
    String username=new String(username.getBytes("ISO8859-1"),"UTF-8");
      

  8.   

    String url = "http://localhost:90/test/login.do?id=" + onlineMd.getId() + "&org=" + java.net.URLEncoder.encode(onlineMd.getOrg(), "utf-8");在接org时
    String org = new String(request.getParameter("org").getBytes("ISO-8859-1"),"UTF-8");
      

  9.   

    这属于get方式传递,在tomcat 中配置一下
      

  10.   

    String url = "http://localhost:90/test/login.do?id=" + onlineMd.getId() + "&org=" + java.net.URLEncoder.encode(onlineMd.getOrg(), "utf-8");这个可以吗。
      

  11.   

    以前的回复,是否可以借鉴?
    http://topic.csdn.net/u/20100604/16/23bfbdbb-94e3-473a-952b-22967a01a0f8.html
     #35楼 得分:0回复于:2010-06-04 22:46:41用这个方法做下转换试试看(DB:ORACLE)。package aa.bb.cc;
    import java.io.*;public class TransFormat {
      // 插入数据库之前使用此方法进行转换
      public static String GBToUnicode(String strIn)
      {
      byte[] b;
      String strOut = null;
      if(strIn == null || (strIn.trim()).equals(""))
      return strIn;
      try
      {
      b = strIn.getBytes("GBK");
      strOut = new String(b,"ISO8859_1");
      }
      catch(UnsupportedEncodingException e)
      {
      }
      return strOut;
      }  // 从数据库取数据库后使用此方法进行转换
      public static String UnicodeToGB(String strIn)
      {
      String strOut = null;
      int strLen = 0;
      strOut = "";  if(strIn == null || (strIn.trim()).equals(""))
      return strIn;
      try
      {
      byte[] b = strIn.getBytes("ISO8859_1");
      strOut = new String(b,"GBK");  // 处理存在半个汉字的情况
      strLen = strOut.length();
      if(strLen == 0)
      {
      String tempStr = null;
      strLen = b.length;
      tempStr = strIn.substring(0,strLen - 1);
      byte[] b1 = tempStr.getBytes("ISO8859_1");
      strOut = new String(b1,"GBK");
      b1 = null;
      }
      b = null;
      }
      catch(Exception e)
      {
      }
      return strOut;
      }  // 一般情况下不调用该方法
      // 两种字符集的转换
      public static String ChangeUnicode(String strIn,
      String SourceCode,String TargetCode)
      {
      String strOut = null;
      if(strIn == null || (strIn.trim()).equals(""))
      return strIn;
      try
      {
      byte[] b = strIn.getBytes(SourceCode);
      strOut = new String(b,TargetCode);
      }
      catch(Exception e)
      {
      }
      return strOut;
      }}
    =====
    a.jsp<%
    out.println(UnicodeToGB(request.getparameter(menthod)));
    %> 
     
      

  12.   

    URLEncoder.encode();最好用作用域request或session
      

  13.   

    IE 的问题,你用 Firefox 就没有问题。把 URI 中的汉字采用:Java: java.net.URLEncode.encode 方法
    JavaScript: encodeURI() 函数使用 URI 编码的话就不会再产生这种问题了。