Solved

Replacing HTML parameters with Java

Posted on 2011-03-06
8
441 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Form Submit falis 6 33
Materializecss - Different Behaviors in Browser's 1 35
send keys not working in vba 7 58
How to create a textarea which saves text in HTML 8 35
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
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…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

785 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