当前位置: 技术问答>java相关
email中中文出现乱码怎么办???
来源: 互联网 发布时间:2015-02-26
本文导语: 参考如下程序发送email: import java.io.*; import sun.net.smtp.SmtpClient; public class mail { public void sendmail(String to,String subject,String content) { String from="xxxx@xxxx.xxx"; try { ...
参考如下程序发送email:
import java.io.*;
import sun.net.smtp.SmtpClient;
public class mail
{
public void sendmail(String to,String subject,String content)
{
String from="xxxx@xxxx.xxx";
try
{
SmtpClient client = new SmtpClient("mail.3wins.com");
client.from(from);
client.to(to);
PrintStream message = client.startMessage();
message.println("To: " + to);
message.println("Subject: "+subject);
message.println(content);
message.println();
client.closeServer();
}
catch (IOException e)
{
System.out.println("ERROR SENDING EMAIL:"+e);
}
}
}
在jsp中调用此javabean,中文发送到的全是乱码,
用了String(str.getBytes(),"GB2312")也没用,请教!!!
import java.io.*;
import sun.net.smtp.SmtpClient;
public class mail
{
public void sendmail(String to,String subject,String content)
{
String from="xxxx@xxxx.xxx";
try
{
SmtpClient client = new SmtpClient("mail.3wins.com");
client.from(from);
client.to(to);
PrintStream message = client.startMessage();
message.println("To: " + to);
message.println("Subject: "+subject);
message.println(content);
message.println();
client.closeServer();
}
catch (IOException e)
{
System.out.println("ERROR SENDING EMAIL:"+e);
}
}
}
在jsp中调用此javabean,中文发送到的全是乱码,
用了String(str.getBytes(),"GB2312")也没用,请教!!!
|
在jsp中转换(像下面这样!)
String from=request.getParameter("from");
String to=(String)request.getParameter("to");
String subject=(String)request.getParameter("subject");
String text=(String)request.getParameter("text");
from=new String(from.getBytes("8859_1"));
to=new String(to.getBytes("8859_1"));
subject=new String(subject.getBytes("8859_1"));
text=new String(text.getBytes("8859_1"));
String from=request.getParameter("from");
String to=(String)request.getParameter("to");
String subject=(String)request.getParameter("subject");
String text=(String)request.getParameter("text");
from=new String(from.getBytes("8859_1"));
to=new String(to.getBytes("8859_1"));
subject=new String(subject.getBytes("8859_1"));
text=new String(text.getBytes("8859_1"));
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。