RSS Forums RSS

get data from HTML form

Please support our Java advertiser: Programming Forums
Reply
Posts: 67
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

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Posts: 705
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 83
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: get data from HTML form

  #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  
Posts: 67
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

  #3  
Oct 23rd, 2008
This is my java code that I have when I hard coded the information
  SMTPSender s = new SMTPSender(); 

    s.setToAddress("email@host.edu");
    s.setFromAddress("email@host.edu");
    s.setSubject("subject");
    s.setBody("this is the body");

    s.sendMessage();
  }
  }
  class SMTPSender{
 	String toAddress;
	public void setToAddress(String a){
		toAddress = a;
		}
	String fromAddress;
	public  void setFromAddress(String b){
		fromAddress = b;
		}
	String subject;
	public  void setSubject(String c){
		subject = c;
		}
	String body;
	public  void setBody(String d){
		body = d;
}
Here is my code for the form
<h1>Mail Page</h1>
 Please type your mail stuff below:
<form action=/mailer>
To:
<input name=toAddress ></input>
</br>
From:
<input name=fromAddress ></input>
</br>
Subject:
<input name=subject ></input>
<br>
Body:
<input name=body ></input>
<br>
<input type=submit></input>
</form>
How do I pass those?
Reply With Quote  
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

  #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  
Posts: 7,398
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: 439
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

  #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 2:07 pm.
I don't accept change; I don't deserve to live.

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.

-- Eric Naggum RIP :-(
Reply With Quote  
Posts: 67
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

  #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  
Posts: 7,398
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: 439
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

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

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.

-- Eric Naggum RIP :-(
Reply With Quote  
Posts: 67
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

  #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  
Posts: 7,398
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: 439
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

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

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.

-- Eric Naggum RIP :-(
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 1402 | Replies: 8 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:17 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC