PDA

View Full Version : Calling Java/Plugin methods from Javascript


jhesse
10-08-2002, 07:03 PM
Hi everybody,

I'm having difficulties getting this to work. I wrote a Java applet for encryption that I would like to call using Javascript. My code looks something like this:

. . .
<APPLET CODE="Encryption.class" NAME="Encryption" WIDTH=600 HEIGHT=100 MAYSCRIPT></APPLET>
. . .
Password: <input type="password" name="password"> <br>
Input Text: <input type="text" name="inputtext"> <br>
<input type="button" name="encryptButton" value="Encrypt" onClick="encrypted.value = document.Encryption.Encrypt(password.value, inputtext.value"> <br>
Encrypted text: <input type="text" name="encrypted" size="50">

Basically I'm calling the Encrypt method in the Java applet, passing in a password and some text from the HTML form, and putting the output in a text field.

This works perfectly in IE 6.0 running in Windows 2000. It doesn't work in Netscape 4.7. It doesn't work in either browser on the Mac. In Netscape, I need to use a Java plugin--the built-in VM gives me "method verification" errors. With the plugin turned on, the applet runs, but when I push the "encryptButton", Netscape gives me a "document.Encryption has no properties" error. Do I need to use different syntax and/or tags to use the Java plugin?

Any ideas on how I can get this to work in all browsers & platforms (or at least Netscape and Macintosh)?

glenngv
10-09-2002, 07:25 AM
try this:

<APPLET CODE="Encryption.class" NAME="Encryption" WIDTH=600 HEIGHT=100 MAYSCRIPT></APPLET>
. . .
Password: <input type="password" name="password"> <br>
Input Text: <input type="text" name="inputtext"> <br>
<input type="button" name="encryptButton" value="Encrypt" onClick="this.form.encrypted.value = document.applets['Encryption'].Encrypt(this.form.password.value, this.form.inputtext.value)"> <br>
Encrypted text: <input type="text" name="encrypted" size="50">

jhesse
10-10-2002, 04:39 PM
Thanks... but that didn't work either.

I think it just won't work in Netscape 4.7... I've read that LiveConnect doesn't work for plugins in that version, and my experience has born that out.

Instead I just hacked my applet to get it to work in the browser's built-in VM, and then LiveConnect works perfectly.