我用java写邮件客户端,邮件的主题若是中文,就不能正常显示。如果主题的内容为:“测试”,则显示为:“=?gb2312?B?suLK1A=?=”。如何用java把其还原为中文?
这是什么意思?“=?gb2312?B?suLK1A=?=”这应该如何分析?gb2312应该是编码格式吧,“=?”这个是编码的起始声明?“?B?”是编码的结束声明?“?=”这个是整个的结束?而中间的“suLK1A=”对应着汉字“测试”?希望大家给予指点!谢谢!!为了感谢大家的参与,下面的三个问题也是我的,每一个都是100分,大家“回复者有分,解答问题者多给分”。其中一个问题(james连接Mysql的那个)我已经解决了,这个就是散分了,现在。http://community.csdn.net/Expert/topic/3979/3979633.xml?temp=.7268946
http://community.csdn.net/Expert/topic/4014/4014734.xml?temp=.5953638
http://community.csdn.net/Expert/topic/4020/4020017.xml?temp=.1423609

解决方案 »

  1.   

    yguanglv(他人笑我做程序,我笑他人搞编程),你说的能详细一点吗?UTF-8的编码格式?还是?
      

  2.   

    帮你顶,一般来讲,java的中文处理,经常由于编码的混乱而导致显示乱码,你可查一下相关的Java中文编码的资料。
      

  3.   

    可以通过以下字符串构造函数来转换:
    public String(byte[] bytes,String charsetName)throws UnsupportedEncodingExceptionConstructs a new String by decoding the specified array of bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array. 
      

  4.   

    public String(byte[] bytes,String charsetName)throws UnsupportedEncodingException
    这个我已经用过了,但还是原来的字符串。
    subject=new String(subject.getBytes(),code);
    subject.getBytes():乱码的源字符串转换为字节
    code是从中提取的gb2312
    但subject不变的
      

  5.   

    我说的是编码格式,你可在显示端设置为UTF-8
      

  6.   

    <%@ page contentType="text/html; charset=UTF-8"%> 或
    <%@ page contentType="text/html; charset=MS932"%> 或
    <%@ page contentType="text/html; charset=HZ"%>
     我电脑是日文系统所以测试不出,你自己试试
      

  7.   

    gb2312才是支持中文吧,UTF-8不支持中文吧
    好像是的
      

  8.   

    <%@ page contentType="text/html; charset=UTF-8"%> 与
    <%@ page contentType="text/html; charset=MS932"%>不行的,还是原来的样子,而且我原来的中文也显示不出来了。
    <%@ page contentType="text/html; charset=HZ"%>
    有问题的,提示:
    org.apache.jasper.JasperException: Unsupported encoding: HZ
      

  9.   

    <%@ page contentType="text/html; charset=Shift_JIS"%>
    这是我环境下的设置,你不防也试试
      

  10.   

    <%@ page contentType="text/html; charset=gb2312"%>
    或则
    <%@ page contentType="text/html; charset=GBK"%>
      

  11.   

    我一直是用的这个:<%@ page contentType="text/html; charset=gb2312"%><%@ page contentType="text/html; charset=Shift_JIS"%>这个是日文的吧大家说的编码格式都不行的
      

  12.   

    最好用<%@ page contentType="text/html; charset=GBK"%>
    这在页面显示上很好用!
      

  13.   

    我不知道
    ,但是从主题来看 suLK1A 绝对不是 GBK编码
    如果是的话,英文,中文的2个字节都是>128的,所以不可显示字符,不知道是不是 base64编码我是弱手,扔鸡蛋没有关系.
      

  14.   

    String code="你需要转换的字符串";
    if((code.startsWith("=?GB2312?B?")&&code.endsWith("?="))||(code.startsWith("=?gb2312?B?")&&code.endsWith("?=")))
    {
         MimeBase64Decoder.translate(code.substring(11,subject.indexOf("?=")));
         code=new String(MimeBase64Decoder.getByteArray());
    }
    code就是转换后的字符串。
    MimeBase64Decoder是jbuilder9所带的一个组件的一个类,有源文件的,你找一下。