• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using JSP's as Template for Email

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may find this helpful:

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

See also:

http://www.stringtemplate.org/
 
reply
    Bookmark Topic Watch Topic
  • New Topic