views:

44

answers:

1

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.

+2  A: 

You should fire a HTTP request on it.

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:

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 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.

BalusC
Hmm. Why don't you think that a JSP is the right tool for the job? Essentially I need to generate HTML and thats what JSP's are all about right?
David Tinker
See answer update.
BalusC
I got this working using request.getRequestDispatcher() and Springs MockHttpServletResponse to capture the output. Thanks for the help.
David Tinker