Send Email with Form information

T

teser3

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

Roedy Green

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

Daniel Pitts

Roedy said:
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.
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.
 
M

Manish Pandit

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

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
 
T

teser3

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
 
R

Roedy Green

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
 
D

Daniel Pitts

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

Lew

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top