我用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
这是什么意思?“=?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
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.
这个我已经用过了,但还是原来的字符串。
subject=new String(subject.getBytes(),code);
subject.getBytes():乱码的源字符串转换为字节
code是从中提取的gb2312
但subject不变的
<%@ page contentType="text/html; charset=MS932"%> 或
<%@ page contentType="text/html; charset=HZ"%>
我电脑是日文系统所以测试不出,你自己试试
好像是的
<%@ page contentType="text/html; charset=MS932"%>不行的,还是原来的样子,而且我原来的中文也显示不出来了。
<%@ page contentType="text/html; charset=HZ"%>
有问题的,提示:
org.apache.jasper.JasperException: Unsupported encoding: HZ
这是我环境下的设置,你不防也试试
或则
<%@ page contentType="text/html; charset=GBK"%>
这在页面显示上很好用!
,但是从主题来看 suLK1A 绝对不是 GBK编码
如果是的话,英文,中文的2个字节都是>128的,所以不可显示字符,不知道是不是 base64编码我是弱手,扔鸡蛋没有关系.
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所带的一个组件的一个类,有源文件的,你找一下。