0

我有一个jsp文件:

电子邮件.jsp

<div id="foo">
    <span id="bar">test</span>
</div>

现在我想通过Java Mail 的 setText 方法发送email.jsp的内容,如下所示:

例如:

email.setText(getFileContent("email.jsp"));

将导致类似:

email.setText("<div id="foo"><span id="bar">test</span></div>");

我怎样才能做到这一点?

4

1 回答 1

0

您可以编写一个实用方法:

 /**
 * @param fileName String: Path of the JSP file 
 * @return jspContent String : contents of the JSP file
 * @throws IOException
 */
private String readJSPContents(String fileName) throws IOException {
    InputStream io = getServletContext().getResourceAsStream(fileName);
    BufferedReader in = new BufferedReader(new InputStreamReader(io));
    String str;
    String jspContent = "";
    while ((str = in.readLine()) != null)
        jspContent+=str;
    in.close();
    return jspContent;
}

然后 ,email.setText(readJSPContents("email.jsp"), "utf-8", "html");

于 2013-04-16T17:24:10.577 回答