Jsp乱码的问题

java2se 2006-03-07 04:58:02
在JSP开发中,在网页上可以显示中文,但在用邮件发送后, 到 邮件接收人那里出来 的乱码,请问各位大侠如何解决
...全文
118 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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");
试看看
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-03-07 04:58
社区公告
暂无公告