permaculture playing cards*
The moose likes Servlets and the fly likes Best way to create a dynamic HTML Email from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Best way to create a dynamic HTML Email from a servlet" Watch "Best way to create a dynamic HTML Email from a servlet" New topic
Author

Best way to create a dynamic HTML Email from a servlet

Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3018
    
  35

Assume a scenario that you need to send a dynamic email from a web application, something like a confirmation email for the user registration. It is easy to create that email, if it is a small email having only few lines. We can create it as a String value, and then send it via JavaMail or any other api. But what if it is a large email having hundreds of html tags with a large content? What is the best way to create it?

I think it is best if we can create that email as a JSP. So we can capture the output stream of that JSP using filters, and assign it to a String variable. But do you think that it is a good practice for here?

Devaka.


Founder of ExamLab and Systemup
See how I can help you to become an awesome programmer
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

A templating technology (such as Velocity) might be a good bet.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3018
    
  35

Paul Sturrock wrote:A templating technology (such as Velocity) might be a good bet.


If I tell you the truth, I didn't know about the 'templating technology' before. Thank you Paul for letting me know about it.

Devaka.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Well, JSP is a templating technology -- which is probably why your initial reaction was to try and use it. But I agree with Paul, using a templating engine would be more striaght-forward than trying to subvert JSP for that usage.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3018
    
  35

Bear is right. I wondered about a 'templating technology', or something else other than JSP. Because it sounds inappropriate when JSP is subverted to that usage.

Thanks,

Devaka.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Best way to create a dynamic HTML Email from a servlet
 
Similar Threads
How can I capture the output of a JSP file and send an email?
Creating a HTTP request in java and getting it's request
How to retrieve generated HTML
a library class or method that is obsolete
about struts