GeeCON Prague 2014*
The moose likes I/O and Streams and the fly likes Pass parameter from JApplet to php file using POST method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Pass parameter from JApplet to php file using POST method" Watch "Pass parameter from JApplet to php file using POST method" New topic
Author

Pass parameter from JApplet to php file using POST method

maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
I have connected my JApplet with one php file, which gets the parameter from my applet and write it to MySQL database. Parameter is passed using textfield - user enters string and confirms it's choice clicking on Submit button.

I have made this connection using GET method, but I have to use POST method for sending parameter. I hope somebody can help me to do that.

Here is how I made connection:

In init() method I wrote:



link is a parameter which I defined in HTML file. It's value is http://localhost/subtest.php.

In my ActionPerformed method for button clicked I wrote:



Submitlink and fileToRead are strings.

Here is my readFile() method:



My subtest.php file looks like this:



Any help to use POST method instead of GET would be appreciated.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
For the applet side, see http://www.exampledepot.com/egs/java.net/Post.html for an example.
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
I wrote in my ActionPerformed method (for button clicked):



but I still don't have insert to the database. Where did I made a mistake?
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Having an empty catch block is rarely a good idea, and definitely a bad one when dealing with I/O.

Does the request ever make it to your server code?
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
No, as far I know. There is no insert to the database (which is done by php file).
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
No, as far I know.

Make sure one way or another (maybe by adding logging statements to your server code).

And be sure to add logging to your applet's exception handlers as well.
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
By server code: do you mean on php file? I am not familiar with PHP, so I am not sure I know to write logging statements there. Can you help me with that?
 
GeeCON Prague 2014
 
subject: Pass parameter from JApplet to php file using POST method