最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Problem with Java Applet <--> Javascript communication - Stack Overflow

programmeradmin2浏览0评论

I'm having trouble getting a Java Applet to municate 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 municating between Java and Javascript that I should be using?

--- More info ---

I'm using the deployJava.js script as provided by Sun to embed the applet on the fly. I made sure MAYSCRIPT is enabled. I know it's not a problem with MAYSCRIPT, because the munication works some of the time.

I'm having trouble getting a Java Applet to municate 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 municating between Java and Javascript that I should be using?

--- More info ---

I'm using the deployJava.js script as provided by Sun to embed the applet on the fly. I made sure MAYSCRIPT is enabled. I know it's not a problem with MAYSCRIPT, because the munication works some of the time.

Share Improve this question edited Mar 22, 2010 at 19:43 davr asked Mar 22, 2010 at 19:33 davrdavr 19.2k17 gold badges80 silver badges99 bronze badges 1
  • Are you using the applet tag to embed it? – Enrique Commented Mar 22, 2010 at 19:39
Add a ment  | 

3 Answers 3

Reset to default 1

Make sure you have MAYSCRIPT in your applet tag.

<applet id="..." code="..." name=".." codebase="..." archive="..."  width="100%" height="100%" MAYSCRIPT>

I think I've solved the problem by setting classloader_cache=false and separate_jvm=true...once I set both of those, the intermittent obscure errors stopped happening. Hopefully this solves the problem for good.

If you set separate_jvm to true this has very bad effect on performance since new Java VM is instantiated for every applet. If you have multiple applets on the page (30+) this is pretty slow.

I wonder if there is any other solution for this issue. E.g., we have multiple applets across multiple tabs. When the first tab with applets is opened all applets are shown correctly with no problems. But, switch to any other tab results with the error for no registered plugin. In IE this error does not occur because in IE all applets are instantiated immediately as they are added to DOM.

发布评论

评论列表(0)

  1. 暂无评论