本站首页    管理页面    写新日志    退出


«November 2025»
1
2345678
9101112131415
16171819202122
23242526272829
30


公告
暂无公告...

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:111
评论数量:190
留言数量:-24
访问次数:642832
建立时间:2007年4月21日




[Java]java语言中中文乱码解决方案
原创空间,  软件技术

赵勇 发表于 2007/7/17 17:55:29

java语言中中文乱码解决方案: dagege: subject = new String(subject.getBytes("ISO8859_1"), "GBK");sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder();msg.setSubject("=?GB2312?B?"+enc.encode(subject.getBytes())+"?=");    RIIT内网中文显示乱码解决办法:开始时新闻的标题(title)和出处(sour),正文(conten)都显示乱码,原因是原来的StringConverter.getChinese()有问题。 在文件package edu.tsinghua.riit.oa.web的文件NewsMail的sendEmail方法中:在张勇老师的指导下把问题解决了,方法就是去掉调用StringConverter.getChinese()方法的语句,另外改用以下代码处理title,  //subject = new String(subject.getBytes("ISO8859_1"), "GBK"); sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder(); message.setSubject("=?GB2312?B?"+enc.encode(title.getBytes())+"?=");  public static String UnicodeToChinese(String s) {  try {   if (s == null || s.equals(""))    return "";   String newstring = null;   newstring = new String(s.getBytes("ISO8859_1"), "gbk");   // System.out.println("to DB:"+newstring);   return newstring;   // return s;  } catch (Exception e) {   return s;  } }  public static String ChineseToUnicode(String s) {  try {   if (s == null || s.equals(""))    return "";   String newstring = null;   // newstring = new String(s.getBytes("ISO8859_1"), "GBK");   newstring = new String(s.getBytes("gbk"), "ISO8859_1");   // System.out.println("to Jsp:"+newstring);   return newstring;  } catch (Exception e) {   return s;  } }


阅读全文(2394) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.469 second(s), page refreshed 144795332 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号