Solved

Replacing HTML parameters with Java

Posted on 2011-03-06
8
436 Views
Last Modified: 2012-05-11
Hi,

As a part of our department requirements, we need to send out HTML emails that are predefined.

These templates are stored in a table.
Please consider the below case
<HTML>
<TR>
<TD>
#NAME#
</TD>
</TR>
</HTML>

Value for the tag #NAME# needs to  be picked up from the database and the HTML template populated accordingly.


Could you please advise, on how this can be achieved with Java ? Any sample code would be highly appreciated.

I have the code ready to send out emails. Only worry is to populate the HTML templates with the values form the database.
Regards
0
Comment
Question by:TJOSY
8 Comments
 
LVL 9

Expert Comment

by:ioanton
ID: 35045878
The Apache Velocity could help you best for this kind of task. For details, check this:

http://velocity.apache.org/engine/devel/user-guide.html
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35046151
You can use JSTL to achieve  this .....

you set the value in java and get the values in Java  like

request.setParameter("name","sathish");

in JSP

<HTML>
<TR>
<TD>
${name}
</TD>
</TR>
</HTML>
0
 
LVL 11

Expert Comment

by:Manish
ID: 35046607
Do you have code to get Name?
http://www.exampledepot.com/egs/java.sql/connectoracle.html

get name value in code and send using mail code.
0
 

Author Comment

by:TJOSY
ID: 35052138
Hi All,

The example I provided was just a sample. In our case the HTML templates are quite large. These are infact some newsletters. that we need to send out to customers periodically.

The java code needs to call the templates(stored as a column in a database table) and then needs to replace the tags with the appropriate value (again picked up from different tables). Then the HTML needs to be emailed.

Regards
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 26

Accepted Solution

by:
mrcoffee365 earned 500 total points
ID: 35060743
Then what you need to do in Java is read in the text from the file which has the email HTML text.  

Get the replacement values from the database.

Replace the "#name#" text strings in the HTML email text with the values from the database.

Which parts do you not know how to do in Java?
0
 

Author Comment

by:TJOSY
ID: 35064266
Thanks mrcoffee365.

You have provided me a simple solution that will serve my purpose.

I can do the coding for that. Now once I replace all the tags with  the values from the database, how can I provide the output HTML to the users ?

Thanks and regards
0
 
LVL 26

Assisted Solution

by:mrcoffee365
mrcoffee365 earned 500 total points
ID: 35065308
You can send mail using JavaMail.   You'll need the list of user email addresses and it would be best to send from a legitimate mail server, probably your department server.

You can get javamail from
http://www.oracle.com/technetwork/java/javamail/index.html

0
 
LVL 26

Expert Comment

by:mrcoffee365
ID: 35069982
Good luck!  You can ask another question if you need help using Javamail.  Also, there are a lot of answers already in EE about it.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now