应该放在最前面,尤其是当是servlet时,要在getWriter之前才起作用

解决方案 »

  1.   

    用下面的代码将中文字符串转为UTF-8格式就可以了public static String toUtf8String(String s) {
    StringBuffer sb = new StringBuffer();
    for (int i=0;i<s.length();i++) {
        char c = s.charAt(i);
        if (c >= 0 && c <= 255) {
    sb.append(c);
        } else {
    byte[] b;
    try {
        b = String.valuesof(c).getBytes("UTF-8");
    } catch (Exception ex) {
        System.out.println(ex);
        b = new byte[0];
    }
    for (int j = 0; j < b.length; j++) {
        int k = b[j];
        if (k < 0) k += 256;
        sb.append("%" + Integer.toHexString(k).
        toUpperCase());
    }
        }
    }
    return sb.toString();
        }
      

  2.   

    new String(rs.getString("filename").getBytes("iso8859_1"),"gb2312")
      

  3.   

    还有,用request传递中文时会对长度进行截断,所以最好不要用request传
      

  4.   

    是一个下载的链接把文件名传进去,应该只能request传吧to :liubin_hit(),早试过了,不行to :ABIAY(YAIBA), get到的已经是乱码了,还可以像那样转换吗
      

  5.   

    已经自己解决了,方法是在用request传值之前,先将要传的值Encode再传,get的时候再将得到的值decode就可以了。
    传值时URLEncoder.encode(filename)
    取值时URLDecoder.decode(filename)