如何从servlet发送jsp页面作为电子邮件的内容?

时间:2021-11-29 11:59:05

Please do post if you have any code snippets? When the email is sent out, inbox should have jsp page. Any code snippets?

如果您有任何代码段,请发布?发送电子邮件时,收件箱应该有jsp页面。任何代码片段?

1 个解决方案

#1


0  

Since the jsp/servlet/chain can be adding dynamic content, the only real way is to grab the resultant HTML from the URL using something like:

由于jsp / servlet / chain可以添加动态内容,唯一真正的方法是使用以下内容从URL中获取结果HTML:

URL url = new URL("http://www.oracle.com/");
byte[] html;
try (InputStream in = new BufferedInputStream(url.openStream());
     ByteArrayOutputStream bout = new ByteArrayOutputStream();) {
   byte[] buffer = new byte[512];
   int read = 0;
   while ((read = in.read(buffer)) != -1) {
       bout.write(buffer, 0, read);
   }
   html = bout.getBytes();
}

If you want the HTML as a String:

如果您希望HTML作为字符串:

String htmlString = new String(html, StandardCharset.UTF-8);

#1


0  

Since the jsp/servlet/chain can be adding dynamic content, the only real way is to grab the resultant HTML from the URL using something like:

由于jsp / servlet / chain可以添加动态内容,唯一真正的方法是使用以下内容从URL中获取结果HTML:

URL url = new URL("http://www.oracle.com/");
byte[] html;
try (InputStream in = new BufferedInputStream(url.openStream());
     ByteArrayOutputStream bout = new ByteArrayOutputStream();) {
   byte[] buffer = new byte[512];
   int read = 0;
   while ((read = in.read(buffer)) != -1) {
       bout.write(buffer, 0, read);
   }
   html = bout.getBytes();
}

If you want the HTML as a String:

如果您希望HTML作为字符串:

String htmlString = new String(html, StandardCharset.UTF-8);