Problem Calling Applet Functions from Java Script

Each time I call the function of my applet with my Java Script, it throws an undefined exception. And my search engine did not help me at all.

here is the link to the site on which I am posting it right now: Host site

Here is my html for inserting an applet:

<object type="application/x-java-applet" id="ClientApp" name="ClientApp" archive="Cal.jar" width="100" height="100"> <param name="code" value="Calendar_Algorithm" /> <param name="mayscript" value="true" /> </object> 

And here is my java script code:

 function test(){ document.writeln("<p> "+"Test"+" </p>"); try{ var s=document.ClientApp.getGreeting(); document.writeln("<p> First: "+s+" </p>"); }catch(err){ document.writeln("<p>Error Caught 1: "+err.description+"</p>"); } try{ var s=document.getElementById('ClientApp').getGreeting(); document.writeln("<p> Second: "+s+" </p>"); }catch(err){ document.writeln("<p>Error Caught 2: "+err.description+"</p>"); } document.close(); } 

I know that it loads the applet because I see gui, and if that helps, this is my init function

 public void init() { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { JLabel lbl = new JLabel(getGreeting()); add(lbl); } }); } catch (Exception e) { System.err.println("createGUI didn't complete successfully"); } } 

here is a link to my full code as well as the Code

I got the feeling that the error is incredibly obvious, but I just do not see it.

Any help would be great!

PS Applet class files are now in the signed jar file.

It will also be located in the webapps folder of the tomcat server, but currently I am accessing it as a local file.

+2
source share
1 answer

From http://www.w3.org/TR/html401/struct/objects.html#h-13.4 about an attribute of an object:

"This attribute names a resource containing a serialized representation of the state of the applet." I predict that this is not what you intended.

Also, if you are using firefox mac, you need the mayscript parameter for LiveConnect (JS-2-Java) interaction.

A way to deploy applets that work:

 <object type="application/x-java-applet" width="100" height="100"> <param name="codebase" value="/applet_dir" /> <param name="code" value="Calendar_Algorithm" /> <param name="mayscript" value="true" /> </applet> 

If you do not have a Java console, you should definitely do this. It is activated in the advanced settings of the Java control panel.

By the way, it works on Chrome Linux! On Firefox Linux, this is not the case. Firefox dislikes that both object and code parameters are specified and that the class names are different.

LiveConnect does not work, especially on a Mac. For an overview, take a look at: applets-missing-information-about-liveconnect-and-deployment Basically, you need to know which parts of LiveConnect to use and which not.

+3
source

Source: https://habr.com/ru/post/1414931/


All Articles