Link to home
Create AccountLog in
Avatar of TJOSY
TJOSYFlag 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
Avatar of ioanton
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
Avatar of 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>
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.
Avatar of 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
Avatar of mrcoffee365
mrcoffee365
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of 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
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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.