This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes having problem in connecting HTML form to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "having problem in connecting HTML form to servlet" Watch "having problem in connecting HTML form to servlet" New topic
Author

having problem in connecting HTML form to servlet

voilet annexton
Greenhorn

Joined: May 13, 2007
Posts: 8
hi

im new in this forum

i want help regarding connecting the form to the servlet i made
im making a website using dreamweaver
in the contact us page i'ave made a form.
This form is supposed to submitt the data about clients to the company.
i'ave made a servlet,compiled,deployed and tested it

my servlet looks like this

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Thanks extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException {

response.setContentType ( "text/html" );
PrintWriter out = response.getWriter();

String f_name = request.getParameter ( "fname" ); // gets first name
String l_name = request.getParameter ( "lname" ); // gets last name
String e_mail = request.getParameter ( "email" ); // gets email
String phone = request.getParameter ( "phn" ); // gets phone no.
String address = request.getParameter ( "add" ); // gets address
String cty = request.getParameter ( "city" ); // gets city
String sta = request.getParameter ( "state" ); // gets state
String pn_code = request.getParameter ( "pincode" ); // gets pin code
String com = request.getParameter ( "comment" ); // gets comments

out.println (" <html> " +
"<body> " +
"<h1 style = text-align : center>" +
" Vardhman Udhyog </h1>" +
"<br>First Name " + f_name +
"<br>Last Name " + l_name +
"<br>email address " + e_mail +
"<br>Phone number " + phone +
"<br>Address " + address +
"<br>City Name " + cty +
"<br>State " + sta +
"<br>Pincode " + pn_code +
"<br>comment " + com );
}
}

and the deployment discriptor looks like this

<servlet>
<servlet-name>thankyou</servlet-name>
<servlet-class>Thanks</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>thankyou</servlet-name>
<url-pattern>/Thanks.do</url-pattern>
</servlet-mapping>

i wrote ACTION Thanks.do
METHOD post

but still im confused whether its write or wrong
and yes my form is not working

please help me by giving suggestions

thnks
voilet
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
my form is not working

What does this mean? Which URL are you accessing, and what is the result?


Ping & DNS - my free Android networking tools app
voilet annexton
Greenhorn

Joined: May 13, 2007
Posts: 8
well i was giving the wrong url, i should have given
ACTION = http://localhost:8080/something/Thanks
after giving this my form was taking the parameters and showing it back

but now i have another problem when the user clicks the submitt button where the form is going to store? how can i retrieve that form?

any suggestions are welcomed.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
I'm not quite sure what you mean by "where the form is stored". You can store the request parameters anywhere you want. The code you posted already accesses them, so if you want to store them permanently somewhere, there should be no problem to do so. Maybe I'm misunderstanding the question?
voilet annexton
Greenhorn

Joined: May 13, 2007
Posts: 8
actually i want to know what happens to the inputted data when the user clicks 'submit' and how to retrive that data?
voilet annexton
Greenhorn

Joined: May 13, 2007
Posts: 8
when i searched about it people gave me advice that i should use the cgi-script but there should be some way to do it directly by using servlet.
i dont have much knowledge about cgi

Is there any way i can redirect my form data to an email address,using servlet
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
there should be some way to do it directly by using servlet.
The code you showed above already does that.

Is there any way i can redirect my form data to an email address, using servlet

The servlet can use the JavaMail API to access an email server you have, and send a mail containing any content you like.
[ May 14, 2007: Message edited by: Ulf Dittmer ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: having problem in connecting HTML form to servlet
 
Similar Threads
having problem related to form submission using servlets
Servlet help
A page not found error
login
how to connect the HTML form with my servlet