• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

having problem in connecting HTML form to servlet

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

my form is not working


What does this mean? Which URL are you accessing, and what is the result?
 
voilet annexton
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic