get data from HTML form

Reply

Join Date: Oct 2008
Posts: 89
Reputation: sfrider0 is an unknown quantity at this point 
Solved Threads: 0
sfrider0 sfrider0 is offline Offline
Junior Poster in Training

get data from HTML form

 
0
  #1
Oct 22nd, 2008
I'm creating a SMTP client. I'm entering the data(to, from, subject, body) in a HTML form. How do I pass that data into the actual Java SMTP client so I can send it? I know how to hardcode the data into the client and send it that way but having trouble with letting the user enter the info. I've tried saving them as strings but had no luck.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: get data from HTML form

 
0
  #2
Oct 23rd, 2008
what exactly do you try?
I think you would be better of using .jsp and java servlets, instead of plain html
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: sfrider0 is an unknown quantity at this point 
Solved Threads: 0
sfrider0 sfrider0 is offline Offline
Junior Poster in Training

Re: get data from HTML form

 
0
  #3
Oct 23rd, 2008
This is my java code that I have when I hard coded the information
  1. SMTPSender s = new SMTPSender();
  2.  
  3. s.setToAddress("email@host.edu");
  4. s.setFromAddress("email@host.edu");
  5. s.setSubject("subject");
  6. s.setBody("this is the body");
  7.  
  8. s.sendMessage();
  9. }
  10. }
  11. class SMTPSender{
  12. String toAddress;
  13. public void setToAddress(String a){
  14. toAddress = a;
  15. }
  16. String fromAddress;
  17. public void setFromAddress(String b){
  18. fromAddress = b;
  19. }
  20. String subject;
  21. public void setSubject(String c){
  22. subject = c;
  23. }
  24. String body;
  25. public void setBody(String d){
  26. body = d;
  27. }
Here is my code for the form
  1. <h1>Mail Page</h1>
  2. Please type your mail stuff below:
  3. <form action=/mailer>
  4. To:
  5. <input name=toAddress ></input>
  6. </br>
  7. From:
  8. <input name=fromAddress ></input>
  9. </br>
  10. Subject:
  11. <input name=subject ></input>
  12. <br>
  13. Body:
  14. <input name=body ></input>
  15. <br>
  16. <input type=submit></input>
  17. </form>
How do I pass those?
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 164
Reputation: orko is an unknown quantity at this point 
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: get data from HTML form

 
0
  #4
Oct 23rd, 2008
Easiest way to use jsp and make sure the server supports jsp. Then in form tag, <form action="mail.jsp" method= post>
Check http://www.jsptut.com/Forms.jsp for details.
A Perfect World
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: get data from HTML form

 
0
  #5
Oct 23rd, 2008
Use JSP's only for presenting data / view purposes only; use servlets for processing. Submit the above form to a servlet which would grab the mail related details, create a SMTPSender instance with the values obtained and do the required task.
Last edited by ~s.o.s~; Oct 23rd, 2008 at 3:07 pm.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: sfrider0 is an unknown quantity at this point 
Solved Threads: 0
sfrider0 sfrider0 is offline Offline
Junior Poster in Training

Re: get data from HTML form

 
0
  #6
Oct 23rd, 2008
Thanks, I'll try that. Is there not just a simple GET command in Java that will get the values?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: get data from HTML form

 
0
  #7
Oct 23rd, 2008
You have a few options. You can either host a web application in a servlet container like Tomcat, submit the form to the servlet which would then do the processing. Or you can either create a standalone GUI/Command Line client which accepts the input from the user and sends the mail.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: sfrider0 is an unknown quantity at this point 
Solved Threads: 0
sfrider0 sfrider0 is offline Offline
Junior Poster in Training

Re: get data from HTML form

 
0
  #8
Oct 24th, 2008
I looked at the above page but I'm not real familiar with jsp or servlets. Could I tokenize and parse the query string that is sent and set each tokenized part to toAddress, ect?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: get data from HTML form

 
0
  #9
Oct 24th, 2008
> Could I tokenize and parse the query string that is sent and set each tokenized part to
> toAddress, ect?

Sent where? Just having a HTML form doesn't help; you need to provide an action which will be executed once the form is submitted. Unless you have your own web application hosted somewhere, this isn't possible; there is nowhere for the data to be submitted.

> I'm not real familiar with jsp or servlets.

Now is a good time; head over to Sun's site for sample applications / tutorial. Either that or just create a simple console driven application.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC