EDIT: Nevermind…one typo and the discovery of a retard-moment fixed everything. Thanks to anyone who spent their time reading this.
Hi.
I’m trying to do something very simple. I want to have an applet running a server, and whenever I receive communications on this server, I want the applet to run a JavaScript method, with a number I get from another server, and show this new number in the browser.
It has been simplified severely, by leaving out all server-code, and for now I just run my update method in the applet constructor. Furthermore I’ve set a fixed number for the update method, instead of the call to the remote server.
The problem I’m having, is that no matter what I do, getParameter cannot find my defined parameter “myparam”, and JSObject is always null. I’ve looked at tonnes of examples and threads with the same problem, but to no avail. Can anyone tell me what I’m doing wrong?
HTML
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function jsUpdateFunction(number){
alert("Received number: " + number);
}
</script>
</head>
<body>
<applet id="CounterApplet" code="dk/cbit/counterApplet/CounterApplet.class" archive="CounterApplet.jar" MAYSCRIPT>
<param name="myparam" value="jsUpdateFunction"/>
</applet>
</body>
</html>
Applet:
import java.applet.Applet;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import netscape.javascript.JSObject;
public class CounterApplet extends Applet {
private JSObject jsObject;
@Override
public void start() {
if(jsObject == null)jsObject = JSObject.getWindow(this);
super.start();
}
public CounterApplet(){
updateJS();
}
private void updateJS() {
System.out.println("Entering updateJS()");
String jsCallbackName = getParameter("myParam");
System.out.println("jsCallbackName: "+jsCallbackName);
/*
* Here, the applet will try to connect to a server, to find out
* which number we've reached. For now, it is replaced by a simple String.
*/
String number = "42";
jsObject.eval(jsCallbackName + "(" + number + ")");
}
}