[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 448
  • Last Modified:

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
0
TJOSY
Asked:
TJOSY
2 Solutions
 
ioantonCommented:
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
 
Sathish David Kumar NArchitectCommented:
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
 
ManishLeadCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
TJOSYAuthor Commented:
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
 
mrcoffee365Commented:
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
 
TJOSYAuthor Commented:
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
 
mrcoffee365Commented:
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
 
mrcoffee365Commented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now