Is it possible to create arbitrary Java objects from JavaScript, i.e.?

LiveConnect is a Mozilla technology that combines Java and JavaScript. Surprisingly, they started supporting it again for the latest versions of Firefox. In Firefox, I can write for example.

var d = new java.util.Date();

or use a namespace Packages.if it is not java.something

var d = new Packages.java.util.Date();

or I could go crazy and call the factory method when swinging

Packages.javax.swing.Box.createVerticalBox();

easily instantiates any Java object. Is there an equivalent that works, i.e.?

+3
source share
6 answers

1.1 1.6 Java, LiveConnect Packages , Firefox. , , Internet Explorer,

new document.applets[0].Packages.java.util.Date().toString();

. -Java-, Java. , JavaFX .

, , JavaScript, , , . Java JavaScript , . JavaScript -, Applet.init().

+1

Internet Explorer, , , , . , .

<applet id="myAppletId" name="myAppletName" ...>

var applet = document.getElementById('myAppletId');
var d = applet.getDateFromApplet();

getDateFromApplet(), java.util.Date.

, , , , , ( NS4, 6 IE 4+ ). getElementById(), var applet = document.myAppletName;.

, , , , :

function checkApplets() {
    var da = document.applets; // document.getElementsByName('applet');?

    if (da.length > 0) {
        for (var ii = da.length; ii-- > 0;) {
            if (!da[ii].isActive()) {
                window.timerId = setTimeout(checkApplets, 250);
                return;
            }
        }

        if (window.timerId) {
            clearTimeout(window.timerId);
        }
    }

    window.appletsLoaded = true;
}

, () <object>, , , , Java JavaScript, .

+5

LiveConnect, JavaScript/Java, Mozilla. .

+4

JSON JAVA? JS JSON, , JS Java.

JavaScript Rhino Java JavaScript. https://developer.mozilla.org/en-US/docs/Rhino_documentation

+2

, , - Java Javascript . , JS API Date, API Java.

Edit: The Java Scripting API ( http://java.sun.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html#jsengine ) seems to be closest to what you are trying to do .

+1
source

Perhaps you can use a DWR or other reverse ajax library that allows you to create server-side Java objects through Javascript objects.

0
source

Source: https://habr.com/ru/post/1715464/


All Articles