Solved

Replacing HTML parameters with Java

Posted on 2011-03-06
8
438 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

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 27

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 27

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
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 …

920 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

14 Experts available now in Live!

Get 1:1 Help Now