我有一个 jsp 文件:
email.jsp
<div id="foo">
<span id="bar">test</span>
</div>
现在我想通过 setText 方法发送 email.jsp 的内容,如下所示:
e.g:
email.setText(getFileContent("email.jsp"));
将导致类似:
email.setText("<div id="foo"><span id="bar">test</span></div>");
我该怎么做?
答案 0 :(得分: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");