I am working on a Mail API module where i have to develop a generic functionality of sending Mails with respect to various functionality in the Appliication.
There is one proposed functionality where the module will expose a method which along with some required parameters will take nane of JSP template.
It expects that this will extract the content of the JSP which will be a well formated mail template and send mail.
Is there any way in JAVA where i can extract the content (HTML) from this JSP page so that i can use that HTML content in to the Mail.
Thanks in advance
You have two paths to go, with the first one being a little shorter:
use
new URL("http://site.com/url/to/page.jsp").openConnection(), get theInputStreamand read the contents – this will be as if your server sends a request to itself and gets the resultuse a
Filterand aHttpServletResponseWrapper, and return a customWriter/OutputStream. Each time something is written to the writer / stream, delegate it to the original object, and also write it somewhere where you can read it from later. This explanation is not sufficient, because this is less likely what you need, but if you are willing to take this path, tell me.That’s, however, not the way this is usually done. You’d better use some templating technology like Freemaker or Velocity for your email templates.