Click to See Complete Forum and Search --> : calling java from javascript


edmusim
December 4th, 2002, 02:00 AM
hi!

I like to call a java file from javascript but run into error indicating unresolved class name. For a classname rd, the error states "rd is null or not a valid class". Can anyone give an idea on how to solve this? Below is my html codes & java sample file. Had been trying for many days but to no avail.

<html>
<head>
<title>Welcome!</title>

<SCRIPT LANGUAGE="JavaScript">

function read()
{
document.rd.reading();
}
</SCRIPT>

</head>
Please click here to begin
<br>
<FORM >
<INPUT TYPE=SUBMIT value="Start!" onClick="read()">

<SCRIPT LANGUAGE="JavaScript">

for(i=0;i<10;i++)
{
document.writeln( "<BR>" + rd.score[i]);
}
</SCRIPT>

</center>
</body>
</html>

import java.io.*;

public class rd
{

public static int MAX = 10;
public static byte[] score = new byte[MAX];

public void reading()
{
.....

}
}

websmith99
December 4th, 2002, 02:16 PM
I'm assuming that the Java file is for a Java applet that is embedded into the document?

If so, then use the DOM to reference the applet and with Liveconnect you can call a method of the applet:

document.applets[0].reading();

Note that you do not need to reference the class, just the method used in that applet.

edmusim
December 4th, 2002, 08:08 PM
is it possible to just call a method in the .class java instead of using applet? the .class java program is to read data from a file at client-side into an array (known as score[]) before sending this array content onto a server. Thus i would like to hide this processing from the html page. Please advice on this. thanks!