在JSP中,怎样将“%E8%BF%99%E6%98%AF%E6%B5%8B%E8%AF%95%E4%BF%A1%E6%81%AF”这样的编码转换成中文?

解决方案 »

  1.   

    urlEncoding zhegelei qu kankan
      

  2.   

    import java.io.UnsupportedEncodingException;
    import java.net.URLDecoder;public class test {
    public static void main(String[] args){
    String str ="%E8%BF%99%E6%98%AF%E6%B5%8B%E8%AF%95%E4%BF%A1%E6%81%AF";
    try {
    System.out.println(URLDecoder.decode(str,"UTF-8"));
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    }
    }
    }这个类就可以把你的乱码解析为中文
      

  3.   

    import java.io.UnsupportedEncodingException;
    import java.net.URLDecoder;public class test {
    public static void main(String[] args){
    String str ="%E8%BF%99%E6%98%AF%E6%B5%8B%E8%AF%95%E4%BF%A1%E6%81%AF";
    try {
    System.out.println(URLDecoder.decode(str,"BGK"));
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    }
    }
    这样就可以转换成中文(其中"GBK"是经过GBK编码的)。
      

  4.   

    那就不要转了,直接不让他生产这种BASE64编码过的文件而生产中文,具体的网上很多,结合你的实际情况就可以解决
    如果硬要转得话
    package cn.itcast.javamail2;import java.io.IOException;
    import sun.misc.BASE64Decoder;
    import sun.misc.BASE64Encoder;public class Base {
    static String str = "我是谁";
    static String str1 = "%E8%BF%99%E6%98%AF%E6%B5%8B%E8%AF%95%E4%BF%A1%E6%81%AF"; public static void main(String[] args) {
    String s = getBASE64(str);
    System.out.println(s);
    System.out.println(getFromBASE64(s));
    } public static String getBASE64(String str) {
    if (str == null)
    return null;
    else
    return (new sun.misc.BASE64Encoder()).encode(str.getBytes());
    } public static String getFromBASE64(String str) {
    if (str == null)
    return null;
    BASE64Decoder decoder = new BASE64Decoder();
    try {
    byte[] b = decoder.decodeBuffer(str);
    String s2 = new String(b, "GBK");
    return s2;
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    return null;
    }
    }
    }
      

  5.   

    LZ这个可以,我的是BASE64编码解码的,主要想告诉你%E8%BF%99%E6%98%AF%E6%B5%8B%E8%AF%95%E4%BF%A1%E6%81%AF是经过BASE64编码然后乱码出来的东西
    import java.io.UnsupportedEncodingException;
    import java.net.URLDecoder;public class Test {
    public static void main(String[] args){
    String str ="%E8%BF%99%E6%98%AF%E6%B5%8B%E8%AF%95%E4%BF%A1%E6%81%AF";
    try {
    System.out.println(URLDecoder.decode(str,"UTF-8"));
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    }
    }
    }