Solved

Replacing HTML parameters with Java

Posted on 2011-03-06
8
442 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Output to HTML in powershell 3 37
Fix Form size HTML 16 30
Asp response.write to clients 6 32
Why is my $_POST not going to results page 10 32
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

685 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