Kamkam asked:
It’s an XML validator applet that must send the url(string) and the isvalid(boolean) from the applet. Php must get those values upon clicking the applet’s process button.
It’s an XML validator applet that must send the url(string) and the isvalid(boolean) from the applet. Php must get those values upon clicking the applet’s process button.


1 Comment to 'How to pass a value from an applet to javascript / php?'
February 13, 2010
Unless you use some sort of AJAX, you can’t. In practice, because of output buffering, Java applets often load after PHP script has completed its run.
Also, recall that (1) Java applets run client-side, while PHP runs server-side, and (2) Java applets run in a confined sandbox, so their ability to interact with the client machine is severely limited.
So you’re looking for a fairly convoluted three-step process:
1. PHP script completes the initial output, including the instructions to load the Java applet.
2. The Java applet, upon clicking the Process button, sends its output to the server via GET or POST (or maybe sockets, which would be faster).
3. A client-side Javascript, meanwhile, keeps polling the server via AJAX waiting to hear that the data expected from the applet has arrived.
Needless to say, you will need some sort of session mechanism, which would uniquely identify each instance of data transmission…
All in all, I think your design is flawed. If you insist on implementing a validator in Java, it should be a server-side JSP page, not a client-side applet…
Leave a comment