简体   繁体   English

如何使用Spring轻松地将JSP页面用作电子邮件模板?

[英]How can I easily use a JSP page as an email template using Spring?

My emails will need to be HTML anyway and I don't want to introduce another HTML generation mechanism (eg Velocity) into my project if I don't have to. 无论如何,我的电子邮件都必须是HTML,如果不需要,我不想在项目中引入其他HTML生成机制(例如Velocity)。 It would be nice if image references in the generated HTML could be converted into attachments automatically. 如果生成的HTML中的图像引用可以自动转换为附件,那就太好了。

You should fire a HTTP request on it. 您应该对此发送一个HTTP请求。

InputStream response = new URL("http://localhost/context/page.jsp").openStream();

If you want to let the JSP access the same session as the current request, do so: 如果要让JSP访问与当前请求相同的会话,请执行以下操作:

String url = "http://localhost/context/page.jsp";
String jsessionid = "jsessionid=" + request.getSession().getId();
InputStream response = new URL(url + ";" + jsessionid).openStream();

Needless to say that JSP is not entirely the right tool for the job. 不用说,JSP是不完全适合工作的正确的工具。 JSP is a webbased view technology, not a standalone template technology. JSP是基于Web的视图技术,而不是独立的模板技术。 Look, you need to fire a whole HTTP request just to get its output. 看,您需要触发整个HTTP请求才能获取其输出。 While not necessarily expensive, this is hacky. 虽然不一定昂贵,但这是很棘手的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM