943,923 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6659
  • Java RSS
Oct 22nd, 2008
0

get data from HTML form

Expand Post »
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.
Similar Threads
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008
Oct 23rd, 2008
0

Re: get data from HTML form

what exactly do you try?
I think you would be better of using .jsp and java servlets, instead of plain html
Reputation Points: 935
Solved Threads: 356
Nearly a Posting Maven
stultuske is offline Offline
2,497 posts
since Jan 2007
Oct 23rd, 2008
0

Re: get data from HTML form

This is my java code that I have when I hard coded the information
Java Syntax (Toggle Plain Text)
  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
Java Syntax (Toggle Plain Text)
  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?
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008
Oct 23rd, 2008
0

Re: get data from HTML form

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.
Reputation Points: 46
Solved Threads: 11
Junior Poster
orko is offline Offline
164 posts
since Apr 2006
Oct 23rd, 2008
0

Re: get data from HTML form

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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Oct 23rd, 2008
0

Re: get data from HTML form

Thanks, I'll try that. Is there not just a simple GET command in Java that will get the values?
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008
Oct 23rd, 2008
0

Re: get data from HTML form

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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Oct 24th, 2008
0

Re: get data from HTML form

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?
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008
Oct 24th, 2008
0

Re: get data from HTML form

> 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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Random Number Generator Question
Next Thread in Java Forum Timeline: Fetching data as Arabic from database??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC