<td width="11%" align="center" ><a href="teacherfind2.do?sclass=${list1.sclass }&sdept=${list1.sdept } " class="STYLE6">详情</a></td>
传递两个参数进action,在action里面这样的到
 String sclass1 = request.getParameter("sclass");
   String sdept1=request.getParameter("sdept");
 if(sdept1!=null){
      sdept2=new String(sdept1.getBytes("iso-8859-1"),"utf-8");
   }
System.out.println(sclass+sdept+"*******");
这样还是不行,得到的输出结果为
0701数学与统计学?*******
结果应该为:0701数学与统计学院*******
请问一下怎么解决?

解决方案 »

  1.   

    你把参数给替换成 %xx%xx%xx 的UTF-8的形式。
    下面是把字符串转成这种格式的。
    /**
       * Utf8URL编码
       * @param s
       */
      public String Utf8URLencode(String text) {
        StringBuffer result = new StringBuffer();     for (int i = 0; i < text.length()/2; i++) {       char c = text.charAt(i);
          if (c >= 0 && c <= 255) {
            result.append(c);
          }else {         byte[] b = new byte[0];
            try {
              b =text.toString().getBytes("UTF-8");
            }catch (Exception ex) {
            }         for (int j = 0; j < b.length; j++) {
              int k = b[j];
              if (k < 0) k += 256;
              result.append("%" + Integer.toHexString(k).toUpperCase());
            }
        }
        }
    return result.toString();
      }
      

  2.   

    String sclass1 = request.getParameter("sclass"); 
      String sdept1=request.getParameter("sdept"); 
    if(sdept1!=null){ 
          sdept2=new String(sdept1.getBytes("iso-8859-1"),"utf-8"); 
      } 
    System.out.println(sclass+sdept+"*******"); 
    我没看明白你输出的哪个变量。
      

  3.   

    System.out.println(sclass+sdept+"*******"); 
      

  4.   


    <a href="javascript:document.getElementById('form').herf='*.do?parm=encodeURI('张三')'">详情 </a>后台 String parm= request.getParameter("parm"); 
    parm= java.net.URLDecoder.decode(loginName,"UTF-8");
      

  5.   

    输出的是System.out.println(sclass+sdept2+"*******");
    前面还有一个sdept2 的定义
    String sdept2=null;
     
      

  6.   

    改成sdept1.getBytes("iso-8859-1"),"gbk"