Open Modular Interactive Mapping Technology
for Visualization of Geophysical Data on the Internet


3.3. Interaction between JavaScript and Java applet on the web page

Currently most of the web-pages using Java-applets, pass the configuration data for the applet through the parameters of the HTML <applet> tag, as illustrated in the following example:.

     <applet archive='mapapplet.jar' name='applet1' code='mapapplet.Main.class' width='450' height='250' MAYSCRIPT>
       <param name='param_name' value='param_value'>
     </applet >

Thus, the configuration parameters are sent from the web page to the applet only once during the page loading and later the applet uses these data. To change the applet configuration, the user has to reload the web page. Data flow from applet back to the web page is impossible in this case.

In contrast, our system supports two-way data exchange between Java applet and HTML form elements and JavaScript on the web page without need of a page reload. Such functions as the MapApplet control by the HTML form elements, data ingest from the MapApplet into the web page HTML form elements to be shown to user or sent back to the database server are based on this technology.

A Java applet on the web page is regarded by the web browser as an XML DOM object. Thus it is possible to call the Java applet methods and to get back their return values from the JavaScript functions on the web page. Here is a sample call of the Java applet applet1 (see the tag above) method function1 with the java.lang.String parameter parameter1 using JavaScript on the web page:

     <SCRIPT LANGUAGE="JavaScript">

Access to JavaScript on the web page from the Java applet is implemented using Java class netscape.javascript.JSObject. During the applet initialization an object of this class is created using the method getWindow(java.applet.Applet):

     JSObject win;
     try {
      win = JSObject.getWindow(this);
     } catch (Exception e) {

After that it is possible to call JavaScript functions on the web page (jsfunc1) with parameters (param1) from the Java applet using this object:


Of course, the function must be defined in JavaScript source on the web page; otherwise a JavaScript error will occur.

Interaction between JavaScript code and Java applet potentially has the following problem. Upon completion of page loading most of the web browsers invoke onLoad JavaScript event. Thus it is possible to trace the loading completion for launching initializing scripts and other actions. But this event can occur before the Java applet initialization, which is not related to the JavaScript onLoad event. So to make the first call from JavaScript to Java, especially within the onLoad event, it is necessary to be certain that the applet initialization is completed. To do that the MapApplet turns JavaScript applet load flag bit into 1 after initialization. Java methods calls from JavaScript have to check this flag value and wait until the applet is loaded and initialized before performing any data exchange between HTML document and applet.

<<< Previous Next >>>