简体   繁体   中英

java call applet method from javascript problem

I have a problem when call applet method from javascript..

I used this function to load applet

$("body").append('<applet id="asra" name="asra" code="akorbulsoundrecorder/recorder.class" archive="http://localhost/.../java/akorbulSoundRecorder.jar" width="300" height="400" MAYSCRIPT></applet>');

and I can call applet function javascript there is no problem;

but

alert(1);
document.asra.stopCapture();
alert(2);

alert(1) and document.asra.stopCapture(); is working but alert(2) doesn't work?

stopCapture function

public void stopCapture() {

    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {



            if(!test)
            jso.call("__appletRecord", new String[] {"stop"});

            targetDataLine.stop();
            targetDataLine.close();


            String filename = audioFile.getAbsolutePath();
            try {
                final ArrayList < String > cmd = getCommand(filename);
                if(!test)
                jso.call("__appletRecord", new String[] {"convertMp3"});
                Main.main(cmd.toArray(new String[cmd.size()]));
                if(!test)
                jso.call("__appletRecord", new String[] {"deleteWav"});
                //audioFile.delete();
            } catch (IOException e1) {
                System.err.println(e1.getMessage());
            }


            try {
                // Establish a connection
                if(!test)
                jso.call("__appletRecord", new String[] {"upload"});
                httpUrlConnection = (HttpURLConnection) new URL("http://localhost/.../java/upload.php").openConnection();
                httpUrlConnection.setDoOutput(true);
                httpUrlConnection.setRequestMethod("POST");
                outputStream = httpUrlConnection.getOutputStream();
                // Buffered input stream
                fileInputStream = new BufferedInputStream(new FileInputStream("c:\\junk.mp3"));
                // Get the size of the image
                totalBytes = fileInputStream.available();
                // Loop through the files data
                for (int i = 0; i < totalBytes; i++) {
                    // Write the data to the output stream
                    outputStream.write(fileInputStream.read());
                    bytesTrasferred = i + 1;
                }
                // Close the output stream
                outputStream.close();
                if(!test)
                jso.call("__appletRecord", new String[] {"success"});
                // New reader to get server response
                serverReader = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream()));
                // Read the servers response
                serverResponse = "";
                while ((response = serverReader.readLine()) != null) {
                    serverResponse = serverResponse + response;
                }
                if(!test)
                jso.call("__appletPHPResponse", new String[] {response});
                // Close the buffered reader
                serverReader.close();
                // Close the file input stream
                fileInputStream.close();
            } catch (IOException ex) {
                jLabel1.setText(ex.getMessage());
            }

            return null; // nothing to return
        }
    });

}

Reason

The reason Java is not working in IE9 is because the Java applet has been blocked by ActiveX Filtering; it is a new feature in IE9. The solution is to temporarily turn off ActiveX Filtering.

1) -> Go to Tools in IE9 and Click on Activex Filtering, then the tick in front of the option will disappear. -> Go到IE9中的工具并点击Activex过滤,然后选项前面的勾会消失。 (It means the option is disabled.) If it is not there the option is already disabled.

If you enabled the Java loading in IE9, you may encounter a problem that the Java causes the web page to crash. We can stop this problem also, by enabling the compatibility view option in IE9. If you enabled Compatibility option then add which address you need to option that contained java applet.

2) -> Go to Tools and click on Compatibility view settings option, then click add button and add the web site. -> Go 到工具并单击兼容性视图设置选项,然后单击添加按钮并添加 web 站点。 To remove a website from Compatibility view, just go back to Compatibility View Settings and remove the site from the Compatibility View list.

You can follow: http://chuyenhang24.com or http://raovat2424.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM