[英]java call applet method from javascript problem
从 javascript 调用小程序方法时出现问题..
我用这个 function 加载小程序
$("body").append('<applet id="asra" name="asra" code="akorbulsoundrecorder/recorder.class" archive="http://localhost/.../java/akorbulSoundRecorder.jar" width="300" height="400" MAYSCRIPT></applet>');
我可以调用小程序 function javascript 没有问题;
但
alert(1);
document.asra.stopCapture();
alert(2);
alert(1)
和document.asra.stopCapture();
正在工作但alert(2)
不起作用?
停止捕获 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
}
});
}
原因
Java 在 IE9 中不起作用的原因是 Java 小程序已被 ActiveX 过滤阻止; 它是 IE9 中的一个新功能。 解决方法是暂时关闭 ActiveX 过滤。
1)如何启用Activex过滤-> Go到IE9中的工具并点击Activex过滤,然后选项前面的勾会消失。 (这意味着该选项被禁用。)如果它不存在,则该选项已被禁用。
如果在IE9中启用了Java加载,可能会遇到Java导致web页面崩溃的问题。 我们也可以通过在 IE9 中启用兼容性视图选项来解决这个问题。 如果您启用了兼容性选项,则将您需要的地址添加到包含 java 小程序的选项中。
2)如何在 IE9 中启用兼容性视图-> Go 到工具并单击兼容性视图设置选项,然后单击添加按钮并添加 web 站点。 要从兼容性视图中删除网站,只需 go 返回兼容性视图设置,然后从兼容性视图列表中删除该站点。
您可以关注: http://chuyenhang24.com或http://raovat2424.Z2C42D102C5FE6AD1C50DA4BEC50Z
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.