JApplet 中 JFileChooser 的使用
JApplet
能否使用 JFileChooser
以便用户可以选择硬盘上的文件? 或者这会违反 Java applet 安全性吗? (我假设正在使用默认安全设置。我不想要求我的用户授予我额外的权限。)
Can a JApplet
use a JFileChooser
so that the user can select a file on his hard-drive? Or would this violate Java applet security? (I'm assuming that the default security settings are being used. I don't want to ask my users to grant me extra permissions.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
此帖子表示您需要先对小程序进行数字签名允许使用
JFileChooser
。This thread indicates that you need to digitally sign your applet before a
JFileChooser
is permitted.如前所述,您需要对小程序进行签名,这会在向用户提供小程序时出现“模糊的安全警告”。 当用户接受运行此小程序时,该小程序将获得完全访问权限并像普通应用程序一样运行,但具有明显的安全隐患。 对于我正在开发的 Web 应用程序,我也处于同样的困境,并且还不确定它是否会得到部署。
如果您正在处理较小的文件,您也可以使用网络浏览器中的内置文件浏览器并从服务器返回文件内容。
此外,您可以针对签名小程序采取的一些安全措施包括:
验证小程序代码的来源。
验证运行小程序的基本 URL。
As mentioned, you need to sign your applet, which result in a "vague security warning" when the user is presented the applet. When the user accept to run this applet, the applet is given full access and functions like an ordinary application with it's obvious security implications. I'm in the same dilemma regarding a web application I'm working on and is not yet sure if it'll get deployed.
You could alternatively use the built-in filebrowser in the webbrowser and bounce back the file-content from your server if you're working with smaller files.
Also, some security measures you can make regarding a signed applet are:
Validating the origin of the applet code.
Verifying the base URL from which the applet was run.
在这种情况下(使用默认设置),您是对的,默认安全管理器不允许访问本地文件。
In that case (of using default settings), you're correct, the default security manager does not allow access to local files.
您可能必须使用 PrivilegedAction 从用户的硬盘驱动器中读取任何内容。 正如 @mmyers 所说,您还必须签署您的小程序。
所以你的答案是肯定的,我以前做过这个,所以我知道这是可以做到的。
You will probably have to use PrivilegedAction to read anything from the user's hard drive. Just as @mmyers said you'll have to sign your applet as well.
So your answer is yes, I've done this before so I know it can be done.