获取 JSP 的内容并在 Java 中通过电子邮件发送
Get content of a JSP and send it via email in Java
我有一个 JSP 文件,其中的内容需要通过电子邮件发送。
想收集文件的内容并替换一些占位符,放在邮件正文中(使用javax.mail)发送出去。
有没有办法用传递的变量渲染 JSP 文件并取回其内容?
首先你需要像这样从jsp读取数据:
import java.net.*;
import java.io.*;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://yourhost.com/index.jsp");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine, data = "";
while ((inputLine = in.readLine()) != null)
data += inputLine;
in.close();
}
}
然后您就可以通过电子邮件发送数据了。
我有一个 JSP 文件,其中的内容需要通过电子邮件发送。
想收集文件的内容并替换一些占位符,放在邮件正文中(使用javax.mail)发送出去。
有没有办法用传递的变量渲染 JSP 文件并取回其内容?
首先你需要像这样从jsp读取数据:
import java.net.*;
import java.io.*;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://yourhost.com/index.jsp");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine, data = "";
while ((inputLine = in.readLine()) != null)
data += inputLine;
in.close();
}
}
然后您就可以通过电子邮件发送数据了。