从javascript问题java调用applet方法

时间:2011-08-14 18:08:13

标签: java javascript applet

从javascript调用applet方法时遇到问题..

我使用此功能加载applet

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

我可以调用applet函数javascript没有问题;

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

alert(1)document.asra.stopCapture();正在运作但alert(2)不起作用?

stopCapture功能

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
        }
    });

}

1 个答案:

答案 0 :(得分:1)

原因

Java在IE9中不起作用的原因是因为Java过滤器阻止了Java小程序;这是IE9的新功能。解决方案是暂时关闭ActiveX过滤。

1)如何启用Activex过滤 - &gt;转到IE9中的Tools并单击Activex Filtering,然后选项前面的勾号将消失。 (这意味着该选项被禁用。)如果不存在,则该选项已被禁用。

如果在IE9中启用了Java加载,则可能会遇到Java导致网页崩溃的问题。我们也可以通过在IE9中启用兼容性视图选项来解决此问题。如果启用了“兼容性”选项,则添加包含java applet的选项所需的地址。

2)如何在IE9中启用兼容性视图 - &gt;转到“工具”并单击“兼容性视图设置”选项,然后单击“添加”按钮并添加网站。 要从兼容性视图中删除网站,只需返回兼容性视图设置并从兼容性视图列表中删除该站点。

您可以关注:http://chuyenhang24.comhttp://raovat2424.com