是否可以连接java服务器,将图片数据与套接字一起发送到HTML页面,然后可以在屏幕上呈现这些图片?
了解如何将HTML页面的响应发送回java服务器也很有帮助。 (例如,如果有人在页面上点击了鼠标)
答案 0 :(得分:0)
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
class SimpleMail1 {
public static void main(String[] args) throws Exception{
System.out.println("Sending mail...");
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.mymailserver.com");
props.setProperty("mail.user", "myuser");
props.setProperty("mail.password", "mypwd");
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("HTML mail with images");
message.setFrom(new InternetAddress("me@sender.com"));
message.setContent
("<h1>This is a test</h1>"
+ "<img src=\"http://www.rgagnon.com/images/jht.gif\">",
"text/html");
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("you@receiver.com"));
transport.connect();
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
}
}