如何使用Spring轻松使用JSP页面作为电子邮件模板? [英] How can I easily use a JSP page as an email template using Spring?

查看:125
本文介绍了如何使用Spring轻松使用JSP页面作为电子邮件模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的电子邮件将需要HTML,我不想在我的项目中引入另一个HTML生成机制(例如Velocity),如果我不需要。如果生成的HTML中的图像引用可以自动转换为附件,那将是很好的。

My emails will need to be HTML anyway and I don't want to introduce another HTML generation mechanism (e.g. Velocity) into my project if I don't have to. It would be nice if image references in the generated HTML could be converted into attachments automatically.

推荐答案

您应该触发HTTP请求

You should fire a HTTP request on it.

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

如果要让JSP访问与当前请求相同的会话,请执行以下操作: p>

If you want to let the JSP access the same session as the current request, do so:

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

不用说,JSP不完全是工作的 工具。 JSP是基于Web的视图技术,而不是独立的模板技术。看,你需要触发一个完整的HTTP请求来获取它的输出。虽然不一定是昂贵的,但这是很奇怪的。

Needless to say that JSP is not entirely the right tool for the job. JSP is a webbased view technology, not a standalone template technology. Look, you need to fire a whole HTTP request just to get its output. While not necessarily expensive, this is hacky.

这篇关于如何使用Spring轻松使用JSP页面作为电子邮件模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆