This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes How to connect and send data to FormMail? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "How to connect and send data to FormMail?" Watch "How to connect and send data to FormMail?" New topic
Author

How to connect and send data to FormMail?

D R Wilkinson
Ranch Hand

Joined: Oct 29, 2004
Posts: 51
Hello,

I am writing an application that has a JDialog which allows the user to send me their requests for new features.

I have created the JDialog and the required fields etc but I do not understand how I can connect to a copy of formmail and send it the data for processing.

I understand the formmail side of things. Can anyone help?

I have supplied the 'Send' JButton ActionListener code as this is where I intend implementing this functionality. I suspect that this connection > data send > disconnection event maybe needs to run within its own thread but I am unsure if this is wise?



Not strictly on topic but... you will notice a chain of getParent() calls. This works but can't be right. How do I find the root parent?

Thank you for reading this.
[ January 17, 2006: Message edited by: D R Wilkinson ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16487
    
    2

When I googled for "formmail", it appears there are several products of that name, but they all convert HTML forms into e-mail in some way. Or maybe those are all versions of the same thing, I couldn't really tell.

Anyway, if it's a URL where you post a form to, then you create a URL object and connect to it. Here's a tutorial about how to do that:

http://java.sun.com/docs/books/tutorial/networking/
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8291

As for your other question, to get the Container of a Component, use javax.swing.SwingUtilities.getRoot() or javax.swing.SwingUtilities.getWindowAncestor().


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
D R Wilkinson
Ranch Hand

Joined: Oct 29, 2004
Posts: 51
Thank you both for your help.

I will post the thread or not in the Thread forum.
D R Wilkinson
Ranch Hand

Joined: Oct 29, 2004
Posts: 51
Again - thanks for your help.

I have read the suggested tutorial and I have set up a free formmail account at FormMail.

I have written the following code and I get an 'ok' response but no email with the form data. I have posted a request for support at FormMail but I thought someone here may know where I am going wrong.



Note : I have changed some of the FormMail account specific information and email addresses to bogus values to protect the account and my email addresses. I know the real values are correct. I suspect the fault lies within my code.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16487
    
    2

I had a quick look through their (tiny) FAQ. It doesn't answer your question specifically but it does have an example where it mentions that you should connect to their service using the POST method. You don't seem to be doing that. Check out the setRequestMethod() method of HttpURLConnection.
D R Wilkinson
Ranch Hand

Joined: Oct 29, 2004
Posts: 51
I received this from Matt at FormMail


Hi Darren,

We're not too familiar with Java here, but there is no reason that if you can
make a web request and submit a form, that it shouldn't work for you. Can
you retrieve the response from formmail.com and see what error it is giving
you? Are you posting to the correct URL and submitting the necessary hidden
fields?

Matt Wright
FormMail.com


I have used the following to try to get a response from the server and 'ok' and 'null' are returned.



I would like to be able to explain precisely what the out.println() statements are sending to the FormMail server but I am not sure.

I think they are sending Strings one after another...

"type=hidden"
"name=_pid"
"value=74639"

... and so on.

Maybe this is the problem? How can I explain to Matt ( not a java progger ) what is being sent to his server by my code so that he can tell me if I am sending the correct information in the correct way?

Thanks for your help so far.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8291

There's a lot to understand and correct in your code. First, it may be instructive for you to read the InputStream from the HttpURLConnection after you send your data. HTTP is a request-response protocol, so reading the response is fulfilling part of the contract, not to mention you may get useful information, like error messages, from the response.
Second, you are sending a lot of unnecessary information. The format of an input field on an HTML page (i.e. <input type=hidden name="subject" value="Your Subject"> ) contains a lot of information about how to display (or not to display) fields to the user. This information does not get passed back in the POST request. Only a series of name-value pairs get passed back (i.e. subject=Your Subject). The name-value pairs are seperated by '&'. Have a look at this example from the Java Almanac.
Third, note in the above example that the value part of the name-value pairs can contain characters which are recognized as HTTP control characters (i.e. space, '=' and so on), so they need to be encoded using URLEncoder.
Those changes should get you a little closer to your goal.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to connect and send data to FormMail?
 
Similar Threads
Painting from one class to another
Access JFrame Components from JDialog
JFrame always on top
input errors in JDialogs
calling and no ringing apparently