Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Send Email with Form information

Thread view: 
teser3@hotmail.com - 24 Oct 2007 03:38 GMT
--------------------------------------------------------------------------------
I have a Form with 10 fields on it and I need to send an email with
all 10 field values.

The form will pass the values to a Servlet which will call a JavaBean
class that will get the values and the email (JavaMail located in an
email helper class) part will be called in the Servelt to send the
JavaBean values. I assume I will also have to use the getMetaData
method to get the field names?

I dont have Struts or Sprint on my Tomcat 4.1.27 container.

Is this the right direction where the Email output will be similiar to
this:
First Name: Joe
Last Name: Smith
City: Dallas
State: Texas
....
Roedy Green - 24 Oct 2007 07:23 GMT
On Tue, 23 Oct 2007 19:38:03 -0700, "teser3@hotmail.com"
<teser3@hotmail.com> wrote, quoted or indirectly quoted someone who
said :

>I have a Form with 10 fields on it and I need to send an email with
>all 10 field values.

I think you will have better luck putting the URL of a form in your
email.  That way you don't need to depend on the email program to
render it and send the data, something I suspect most email programs
would be reluctant to do.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Daniel Pitts - 24 Oct 2007 17:22 GMT
> On Tue, 23 Oct 2007 19:38:03 -0700, "teser3@hotmail.com"
> <teser3@hotmail.com> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 7 lines]
> render it and send the data, something I suspect most email programs
> would be reluctant to do.
Either you or I misinterpreted what the OP wanted.  I understood him
wanting to have a web page with a form, that when he submitted it, an
e-mail was generated from the values in the form.

I didn't reply earlier, because I didn't feel like explaining the
processes of form submission, and how to retrieve the query args from
the request object, and then also connect to the JavaMail API to send
e-mail.

Hopefully, they can look into the JavaMail API themselves, and figure
out what they want to do.

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

teser3@hotmail.com - 25 Oct 2007 18:11 GMT
Thanks, I am sending form info to people using JavaMail API.

I wanted to use getParameterMap() and Enumeration but it seems to
randomly
place the values in micleaneous order:

First Name: Joe
Last Name: Smith
City: Dallas
State: Texas

ends up looking like this sometimes:
City: Dallas
First Name: Joe
State: Texas
Last Name: Smith
Daniel Pitts - 25 Oct 2007 22:25 GMT
> Thanks, I am sending form info to people using JavaMail API.
>
[quoted text clipped - 12 lines]
> State: Texas
> Last Name: Smith

Form submission doesn't guaranty order of form elements. Neither does
the Map interface.  If you know before hand what the value are, then you
can do something like this:

private static final List<String> keys = Arrays.asList("First Name",
"Last Name", "City", "State");

public void printValues(Map<String, String> map) {
   for (String key: keys) {
     System.out.println(key + ": " + map.get(key));
   }
}

HTH.
Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Lew - 25 Oct 2007 23:07 GMT
teser3@hotmail.com wrote:
>> Thanks, I am sending form info to people using JavaMail API.
>>
>> I wanted to use getParameterMap() and Enumeration but it seems to
>> randomly
>> place the values in micleaneous order:

How are you getting an Enumeration?  There is no method in java.util.Map to
return an Enumeration.

Signature

Lew

Roedy Green - 25 Oct 2007 20:21 GMT
On Wed, 24 Oct 2007 09:22:46 -0700, Daniel Pitts
<newsgroup.spamfilter@virtualinfinity.net> wrote, quoted or indirectly
quoted someone who said :

>Either you or I misinterpreted what the OP wanted.  I understood him
>wanting to have a web page with a form, that when he submitted it, an
>e-mail was generated from the values in the form.

I thought he wanted to send somebody an email with an embedded form.
The user would enter data and it would be sent to a server.

For email generated from values in a form, see
http://mindprod.com/jgloss/javamail.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Manish Pandit - 24 Oct 2007 20:10 GMT
On Oct 23, 7:38 pm, "tes...@hotmail.com" <tes...@hotmail.com> wrote:
> --------------------------------------------------------------------------------
> I have a Form with 10 fields on it and I need to send an email with
[quoted text clipped - 15 lines]
> State: Texas
> ....

You would not need to use reflection to get the field names (not sure
where the getMetaData API is coming from). In the servlet, you can
parse the request parameters by calling getParameterMap() on the
request. This will give you a map with key as the parameter name (the
name that you give in the form as <input type="text"
name="somename">), and the value is a String[]. Unless you have
checkboxes in the form, you should only worry about [0]. You can then
construct the email text by using parameter name and the value(s).

-cheers,
Manish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.