Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using JSP's as Template for Email  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the past I have used Velocity for templating my Emails that my app sent. However, at the time I was also using velocity for my everyday view instead of JSP's. Because of this my velocity engine was already loaded and initialized for the webapp.

The problem now is since I am not using Velocity as the view, using Velocity in my webapp is pretty much the same as using it in a stand alone app. And the operation of initializing Velocity is pretty heavy and slows the response down back from the server after I submit a page that sends an Email.

Also, I am trying to use as little 3rd party API's as possible to keep the app as small and simple as possible. What I want to do is use JSP's for templating my email. Here is my initial thought on how to do this. I hope someone can show me a better way.

I thought that I could use a URLConnection and it's InputStream to read the URL of one of my templates (JSP's) and then read each line throwing it into a StringBuffer and returning a String, so something like:



What I don't like is it seems very hacky to do it this way. Is there a better way?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36406
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg,
There isn't really a shorter way to do it. I would read from the local file system instead of a URL though for two reasons:
1) I prefer not to have JSPs visible to the world
2) It's likely to be faster not going through the internet. Especially if you have firewalls.

Out of curiousity, is this really a JSP or HTML code in a JSP?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Gregg,
There isn't really a shorter way to do it. I would read from the local file system instead of a URL though for two reasons:
1) I prefer not to have JSPs visible to the world
2) It's likely to be faster not going through the internet. Especially if you have firewalls.

Out of curiousity, is this really a JSP or HTML code in a JSP?


It's a JSP because there will be dynamic data included in the page before the email is sent. Further thinking leads me to believe this isn't going to work at all. I'd need someway to get the dynamic data in the page and requesting a page with URLConnection will give me an entirely seperate session.

Long story short, looks like I am going to have to use Velocity (Or Freemarker). I'll just have to see how I can get it configured so that it all gets init'd when the webapp starts.
 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may find this helpful:

http://wiki.apache.org/jakarta-velocity/VelocityMail

See also:

http://www.stringtemplate.org/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!