Communication between Java, Java Applet with JavaScript

xiaoxiao2021-03-06  63

Abstract: This article focuses on web development, through flexible use of JavaScript methods to access JavaScript applets from JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript, using JavaScript technology, using JavaScript, using JavaScript technology, using JavaScript technology, using JavaScript in Java Applet applet The mutual supplement of web development languages ​​to develop a more perfect web application.

JavaScript is a development language for HTML environments that provides scripts that can respond to web page events, which fully access all aspects of the browser window, good at merging HTML, Java Applet applet, insert, server program, and other web components, Form a fully integrated web application. And Java is a powerful famous development language that supports the development of web applications. It is used to develop advanced web objects and provide executable content embedded in the web page. It has a stronger programming function, which can be used as a good supplement to JavaScript features. However, these features are limited in a limited browser window area.

Java and JavaScript can complement each other to develop a more perfect web application. This article summarizes the use of the author's programming, involving some methods for the issue of visiting between JavaScript and Java, Java Applet, for reference only.

First, access Java method from JavaScript

In the HTML script, you can use JavaScript to directly call the method in Java, just use "java.lang." Before calling the statement. The specific statement is shown in the following example:

Java.lang.system.out.println ("Hello!")

But this method is only applicable to Netscape Navigator, which is generally not advocated in a web application.

Second, the methods and variables in the Java Applet applet from JavaScript

The JavaScript code can access the variables and methods of Java by JavaScript, the JavaScript code can access the variables and methods of Java, the specific steps, and the use of the law, as below. It should be noted that the Applet object provided by JavaScript has a Name property, without a method and event processor.

step:

1) The method and variable of the Java Applet applet to be accessed is declared as public, and must be declared in the public class;

2) The Java Applet applet should be loaded first to access, although the Applet object does not define an OnLoad event, but you can specify the ONLOAD event processor using the Window object in the flag of the HTML document;

3) The Java Applet applet can be accessed with the JavaScript Applet object.

Example:

"Mytest.htm"