Avatar of TJOSY
TJOSY
Flag for United Arab Emirates asked on

Replacing HTML parameters with Java

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
JSPHTML

Avatar of undefined
Last Comment
mrcoffee365

8/22/2022 - Mon
ioanton

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
Sathish David Kumar N

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>
Manish

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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
TJOSY

ASKER
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
ASKER CERTIFIED SOLUTION
mrcoffee365

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
TJOSY

ASKER
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
SOLUTION
mrcoffee365

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mrcoffee365

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.