Jsp乱码的问题

java2se 2006-03-07 04:58:02
在JSP开发中,在网页上可以显示中文,但在用邮件发送后, 到 邮件接收人那里出来 的乱码,请问各位大侠如何解决
...全文
148 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sheep219 2006-06-06
  • 打赏
  • 举报
回复
这个是我发邮件的一个方法。注释部分是采用gmail服务器
sheep219 2006-06-06
  • 打赏
  • 举报
回复
public void postMail(String to,String sb,String con)
throws MessagingException,Exception
{
String[] recipients = new String[1];
recipients[0] = to;
if (recipients != null && recipients.length > 0)
{
/*String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", "smtp.gmail.com");
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.auth", "true");

PopupAuthenticator pauth = new PopupAuthenticator("pandahallyq@gmail.com", "313131");
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Session session = Session.getInstance(props,pauth);
Message msg = new MimeMessage(session);
*/
String contentType = "html";
Properties props = new Properties();
props.put("mail.smtp.host","smtp.163.com");
props.put("mail.smtp.auth","true");
props.put("mail.smtp.user", "itecheasy@163.com");
props.put("mail.smtp.password", "61664774");
Session session = Session.getInstance(props, new PopupAuthenticator("itecheasy@163.com", "61664774"));
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress("itecheasy@163.com");msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// 设置邮件标题,中文编码
sb = MimeUtility.encodeText(sb, "GBK", "B");
msg.setSubject(sb);
if (contentType == null || contentType.equals("text"))
{
msg.setText(con);
}
else if (contentType.equals("html"))
{
BodyPart bodyPart1 = new MimeBodyPart();
bodyPart1.setContent(con, "text/html;charset=gbk");
Multipart mmp = new MimeMultipart();
mmp.addBodyPart(bodyPart1);
msg.setContent(mmp);
}
msg.setSentDate(new java.util.Date());
Transport.send(msg);
}
}
vacuumboy 2006-06-06
  • 打赏
  • 举报
回复
应该是编码的问题,如果邮件内容是unicode字符,对方必须给自己的浏览器设置为utf-8编码
scottwhb 2006-04-24
  • 打赏
  • 举报
回复
把code贴出来看看
vacuumboy 2006-03-07
  • 打赏
  • 举报
回复
在接收页面开始加一句request.setCharEncoding("gb2312");
试看看

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧