I'm not sure this is the correct forum, but here goes. I may have asked this question before, if so I apologise.
Ok my java chess applet is hosted on a web server on the net somewhere. I have created some user interactivity with mySQL by having an HTML form send data to a php script which queries the mySQL server then dynamically creates html code including param tags which feeds the queried data to my chess applet via the init() method. So far so good.
I'd like to have data that originates with my (client side) applet feed back to mySQL on the server. It has been suggested to me that I should use Ajax to call a php script. My initial research says this doesn't sound right. i.e. Ajax is browser scripting which uses something called XMLHttpRequest to speak asynchronously to the Web Server. That in itself is ok, except intuitively it doesn't seem right that my java applet should have to talk to a browser script in order to gt the job done.
So, I'd appreciate some insight from someone who has been down this road, or knows the technology. I just need to know where I should focus my attention.
I should point out that I am using a free webhosting service that has limited functionality, and that means no server side java.
I don't see why your applet code shouldn't send the HTTP requests directly to the server and handle the response itself.
Joined: May 13, 2009
Paul Clapham wrote:I don't see why your applet code shouldn't send the HTTP requests directly to the server and handle the response itself.
That confirms what I was thinking. The java.net package suggests itself, in particular there is the URLConnection and HttpURLConnection classes, so I guess I start there. I suppose that, as in HTML forms, there is some kind of POST function in one of these classes that works in a similar fashion to the POSTing of HTML form data to php. As far as handling the response goes, that shouldn't need to be anything more than a confirmation that the called php script was succesful in inserting the data that was posted to it by java.
Anyways, I'm just thinking out loud here, we'll see how it goes.
Yes, that's right. You can write your own HTTP-POST code using those classes or you could use the Apache HttpClient open-source package. Using Apache means you don't have to deal with all the grubby details of HTTP (especially the POST method) but it also means that its jar file increases the size of your applet download.
Yup. Just to be clear on one thing: you couldn't talk directly to MySQL from an unsigned applet. That violates sandbox rules. Plus, opening a MySQL port directly onto the open Internet it just begging for trouble.
Proxying the request through a servlet or PHP application is a process known as "HTTP Tunnelling". It's a time-honored tradition that I was using all the way back in 2000, long before the word "AJAX" meant anything other than a Greek warrior or a cleaning product.
Java's URL Request classes make this process quite simple - even the cookies are automatically handled for you. You can pretty much do and HTTP GET or POST request that you would have done via a browser. Which means that if you stick to text, it's easy to test outside the applet.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: May 13, 2009
Thanks Tim, duly noted. I don't think I knew about HTTP Tunneling, but it will give me a new angle from which to search for information