views:

211

answers:

3

I have a website that uses JSP as its view technology (and Spring MVC underneath). Unfortunately, JSP is just a pain to use for anything that doesn't involve an HTTP session. I would like to be able to occasionally send my users some email, and I want to use something JSP-like to render the email's contents. Technologies I'm aware of include:

  • JSP -- It can be forced to work for this sort of thing, I think. Very worst case, I could request the page from my own webserver and render that into an email (ugh!)
  • Velocity -- I've heard good things about this one, and am leaning towards it.
  • StringTemplate -- Looks okay, but I'm worried that no new releases have come out in a year.

Is there a preferred technology for templating in a Java system? Would folks generally recommend Velocity? Is there a good way to use JSP for more generic tasks?

+5  A: 

You should go with Velocity. It's easy to learn and has a low dependency and implementation footprint, especially when using Spring.

But, if it's just one Use Case, you should stick with the String and unless you have no time for experiments ;)

oeogijjowefi
If non-programmers are allowed (or required) to edit those Mail Templates (like it's the case in many companies), than you should definitely use only Velocity since it has the simplest syntax and it's the most one can expect from non-programmers to learn. Our experience was that anything more it's just too much for most of them.
A. Ionescu
+6  A: 

I used Freemarker a lot for e-mail templating and it worked great and was easy to use.

yalestar
+1 for Freemarker. It has the edge over Velocity for me, it has a more expressive template language, it's better documented, and still actively maintained.
skaffman
+1  A: 

I have used StringTemplate several times successfully for sending emails. It is simple and extremely easy to integrate.

The simplicity of StringTemplate makes it straightforward to substitute different parts of the message, for example, subject. Not sure how to do this with Velocity.

I wouldn't worry about the release frequency -- maybe it is just good enough and doesn't need to be actively developed any more.

Sasha O
re: Release frequency - it's just fundamentally powerful and does what is needed. The reason it doesn't have releases very often is because it specifically aims not to have the "features" of the logic based template engines. e.g. in StringTemplate, the template is only allowed to use what you pass it - bare minimum logic, highly modular reusable design -> templates
Stephen