简体   繁体   English

java 调用小程序方法从 javascript 问题

[英]java call applet method from javascript problem

I have a problem when call applet method from javascript..从 javascript 调用小程序方法时出现问题..

I used this function to load applet我用这个 function 加载小程序

$("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;我可以调用小程序 function javascript 没有问题;

but

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

alert(1) and document.asra.stopCapture(); alert(1)document.asra.stopCapture(); is working but alert(2) doesn't work?正在工作但alert(2)不起作用?

stopCapture function停止捕获 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; Java 在 IE9 中不起作用的原因是 Java 小程序已被 ActiveX 过滤阻止; it is a new feature in IE9.它是 IE9 中的一个新功能。 The solution is to temporarily turn off ActiveX Filtering.解决方法是暂时关闭 ActiveX 过滤。

1) How to Enable Activex filtering -> Go to Tools in IE9 and Click on Activex Filtering, then the tick in front of the option will disappear. 1)如何启用Activex过滤-> 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.如果在IE9中启用了Java加载,可能会遇到Java导致web页面崩溃的问题。 We can stop this problem also, by enabling the compatibility view option in IE9.我们也可以通过在 IE9 中启用兼容性视图选项来解决这个问题。 If you enabled Compatibility option then add which address you need to option that contained java applet.如果您启用了兼容性选项,则将您需要的地址添加到包含 java 小程序的选项中。

2) How to Enable Compatibility view in IE9 -> Go to Tools and click on Compatibility view settings option, then click add button and add the web site. 2)如何在 IE9 中启用兼容性视图-> 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.要从兼容性视图中删除网站,只需 go 返回兼容性视图设置,然后从兼容性视图列表中删除该站点。

You can follow: http://chuyenhang24.com or http://raovat2424.com您可以关注: http://chuyenhang24.comhttp://raovat2424.Z2C42D102C5FE6AD1C50DA4BEC50Z

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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