简体   繁体   English

JFileChooser在通过JS调用时导致AccessControlException,在通过applet调用时起作用

[英]JFileChooser causes AccessControlException when invoked through JS, works when called through applet

I'm working on a helper applet to manage transfers of large files. 我正在开发一个帮助小程序来管理大文件的传输。 We currently have an applet that manages the full transaction, from selecting the folder containing the files, transferring them, and reporting on success and failure of the operation, but it's very unsatisfactory in a number of ways. 我们目前有一个applet来管理完整的事务,从选择包含文件的文件夹,传输它们,以及报告操作的成功和失败,但它在很多方面都非常不令人满意。 So now we just want very subtle assistance from applets to let the user find a folder on their local machine and manage the transfer. 所以现在我们只需要applet的非常微妙的帮助,让用户在本地机器上找到一个文件夹并管理传输。 We'd like as much as possible of the feedback and user interaction to use Web-based controls. 我们希望尽可能多的反馈和用户交互来使用基于Web的控件。 So as you can imagine this requires fairly extensive use of the bridge between applets and Javascript in the browser. 因此,您可以想象这需要在浏览器中相当广泛地使用applet和Javascript之间的桥梁。

For the most part this is fairly straightforward, but I've found a weird edge case. 在大多数情况下,这是相当简单的,但我发现了一个奇怪的边缘情况。 I have a method that pops up a JFileChooser dialog and looks at the contents of that folder and reports it back. 我有一个方法弹出一个JFileChooser对话框,然后查看该文件夹的内容并将其报告回来。 I have this working when I create a JButton in the start() method and use that to pop up the JFileChooser. 当我在start()方法中创建JButton并使用它来弹出JFileChooser时,我有这个工作。 But I put all the code for the JFileChooser into a method called showFolderSelect() so that I could also try opening the JFileChooser from Javascript. 但是我将JFileChooser的所有代码放入一个名为showFolderSelect()的方法中,这样我也可以尝试从Javascript打开JFileChooser。 So this call from within the applet works: 所以这个来自applet的调用工作:

public void actionPerformed(ActionEvent event) {
    if ("browse".equals(event.getActionCommand())) {
        showFolderSelect();
    }
}

But this call from Javascript does not: 但是来自Javascript的这个调用不会:

function selectFolder() {
    var infoApplet = document.getElementById('infoApplet');
    infoApplet.showFolderSelect();
}

The Javascript call gets me the following message in Opera's console: Javascript调用在Opera的控制台中收到以下消息:

[5 October, 2003 6:26:56 AM] JavaScript - http://localhost:8080/applet-webapp/
Event thread: click
Uncaught exception: Error: java.security.AccessControlException: access denied (java.util.PropertyPermission user.home read)
Error thrown at line 20, column 12 in selectFolder() in http://localhost:8080/applet-webapp/:
   infoApplet.showFolderSelect();
called from line 1, column 0 in <anonymous function>(event) in http://localhost:8080/applet-webapp/:
   selectFolder();

Any ideas on how I can get this to work from Javascript? 关于如何通过Javascript实现这一点的任何想法? Or am I just going to have to use the JButton created in the start() method of the applet? 或者我只是要使用在applet的start()方法中创建的JButton?

Please note that I can't expect users to be able to monkey around with java.policy configurations or anything like this. 请注意,我不能指望用户能够使用java.policy配置或类似的东西。 The only nod to security and access control that we can expect is that the applet(s) is(are) digitally signed. 对我们可以预期的安全性和访问控制的唯一点头是applet(经过数字签名)。

Thanks for any help or insight on this issue. 感谢您对此问题的任何帮助或见解。

I think this illustrates what Java can do and what JavaScript cannot. 我认为这说明了Java可以做什么以及JavaScript不能做什么。 It looks like JavaScript is not allowed to call methods that allow access to the client system. 看起来JavaScript不允许调用允许访问客户端系统的方法。 Maybe JavaScript access to Java code is restricted to what would be allowed by an unsigned applet. 对Java代码的JavaScript访问可能仅限于未签名的applet所允许的内容。

I can't imagine any way of getting around that if this is just a limitation in the Java - JavaScript bridge. 如果这只是Java-JavaScript桥的一个限制,我无法想象任何解决方法。 And to me it looks like it is. 它对我来说看起来像是。

If you are unhappy with the overall user experience within the applet, consider moving this to JavaFX instead of a pure browser interface with JavaScript. 如果您对applet中的整体用户体验不满意,请考虑将其移至JavaFX而不是使用JavaScript的纯浏览器界面。

Check out the Java FX Ensemble gallery for a list of the UI components you can use. 查看Java FX Ensemble库,获取可以使用的UI组件列表。

On most modern Web browsers, JS applications may only open File dialogs in response to a user action. 在大多数现代Web浏览器中,JS应用程序只能打开“文件”对话框以响应用户操作。 Thus, you can create an Open File dialog from an onclick handler (including, apparently, a handler in a Java applet), but not from eg an onload handler. 因此,您可以从onclick处理程序(显然,包括Java applet中的处理程序)创建“打开文件”对话框,但不能从例如onload处理程序创建。

Thus, you may need to create a button or <a href="#"/> for the user to click on, then call showFolderSelect() while inside that event handler. 因此,您可能需要创建一个按钮或<a href="#"/>以供用户单击,然后在该事件处理程序内调用showFolderSelect()

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

相关问题 java.security.AccessControlException:在浏览器上运行小程序时,访问被拒绝 - java.security.AccessControlException: access denied when running applet on browser 当我尝试在jsp上运行applet时出现AccessControlException - AccessControlException when i'm trying to run applet on jsp 签名的applet在从javascript调用时给出AccessControlException:访问被拒绝 - signed applet gives AccessControlException: access denied, when calling from javascript 从Applet使用JSch连接到SFTP服务器时出现AccessControlException - AccessControlException when connecting to a SFTP server using JSch from an Applet 从JavaScript调用时,已签名的Java Applet会提供AccessControlException - Signed Java Applet gives AccessControlException when calling from JavaScript java.security.AccessControlException:运行小程序时发生 - java.security.AccessControlException: Occured when Running an applet 显示对话框时,JFileChooser导致UnsatisfiedLinkError - JFileChooser causes UnsatisfiedLinkError when showing dialog 部署为jnlp时,在JavaFX中加载图像会导致AccessControlException - Loading image in JavaFX causes AccessControlException when deployed as jnlp 在js中调用时,java applet requestFocus()方法错误 - java applet requestFocus() method error when called in js 服务器未启动时,通过Webstart启动小程序没有错误消息 - No error message launching applet through webstart when server not stared
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM