Problem with Java Applet <--> Javascript communication

Posted by davr on Stack Overflow See other posts from Stack Overflow or by davr
Published on 2010-03-22T19:33:45Z Indexed on 2010/03/22 19:41 UTC
Read the original article Hit count: 586

I'm having trouble getting a Java Applet to communicate with the Javascript code on the page the applet is hosted on. It works sometimes, but othertimes it throws an obscure exception, that googling for has not turned up any useful information, besides a few Java bug reports that were never resolved (thanks Sun).

Here is the code I am using:

JSObject win = JSObject.getWindow(this);
Object[] args = new Object[1];
args[0] = "test argument";
String result = (String) win.call("testJSfunc", args); // XXX

Here is the exception I get on the line marked // XXX. Note that it is intermittent. Often it works, but sometimes it does not, using the same exact code. Reloading the page repeatedly will produce the error pretty quickly.

netscape.javascript.JSException: No registered plugin for applet ID 1
    at sun.plugin2.main.client.MessagePassingJSObject.newJSException(Unknown Source)
    at sun.plugin2.main.client.MessagePassingJSObject.waitForReply(Unknown Source)
    at sun.plugin2.main.client.MessagePassingJSObject.call(Unknown Source)
    at TestApplet.testCallJS(TestApplet.java:159)
    at TestApplet.init(TestApplet.java:139)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Is there another more stable way of communicating between Java and Javascript that I should be using?

© Stack Overflow or respective owner

Related posts about java

Related posts about java-applet