java - 如何使用 HTML 中的嵌入 Java 应用程序访问本地文件系统

标签 java html java-web-start japplet

我只是不知道应该输入什么正确的代码,我已经尝试了很多方法来获得读写权限。我的主要目标是当我单击 Java 应用程序中的按钮时,下载将开始。

最佳答案

您无法从 Java 沙箱小程序访问本地文件系统。阅读文档 What Applets Can and Cannot Do ,你会看到:

Sandbox applets cannot perform the following operations:

  • They cannot access client resources such as the local filesystem, executable files, system clipboard, and printers.

  • They cannot connect to or retrieve resources from any third party server (any server other than the server it originated from).

  • They cannot load native libraries.

  • They cannot change the SecurityManager.

  • They cannot create a ClassLoader.

  • They cannot read certain system properties. See System Properties for a list of forbidden system properties.

如果你想绕过这些限制,你必须使用特权小程序:

Privileged applets do not have the security restrictions that are imposed on sandbox applets and can run outside the security sandbox.

为此,您需要 sign your jar并在 JNLP 中添加以下代码片段文件:

<security>
   <all-permissions/>
</security>

然后用户必须授予权限。来自文档:

The first time an RIA is launched, the user is prompted for permission to run. The dialog shown provides information about the signer's certificate and indicates if the RIA requests permission to run outside the sandbox. The user can then make an informed decision about running the application.

阅读Security in Rich Internet ApplicationsDeploying With the Applet Tag获取更多信息。

关于java - 如何使用 HTML 中的嵌入 Java 应用程序访问本地文件系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30228131/

相关文章:

html - bootstrap html中的两条虚线

java web start代码库证书链

Java Web Start - 使用另一个 native 依赖项加载 native 依赖项

java - 通过添加 '.' 、 ',' 、修剪(不四舍五入)使双倍可读,因此只有最后 2 位数字可能?

java - org.hibernate.MappingException : Unknown entity

java - Jackson 2 和 Spring Autowired bean

macos - 强制VM以32位模式启动WebStart JNLP

java - Spring Boot Web 应用程序没有缓存控制 header

html - 如何使 div 中的图像响应?

html - 子与父 Z-index 问题