在小程序中读写文件
我正在将读取和写入文件的 jar 转换成小程序。在我添加读写功能之前它会正常显示。然后 Firefox 仅显示一个黑框(没有错误弹出窗口)。
我做了很多研究,似乎为了让它工作,我需要对小程序进行签名,然后它会请求用户许可,但是我也读到我无法让小程序写入文件,并且它必须是服务器端。
所以我的问题是我可以让小程序在没有服务器端脚本的情况下读取和写入文件吗? 如果是这样,我如何让我的小程序签名(我读了一些教程,但我对此有点陌生)。
I was in the process of turning my jar that reads and writes files into an applet. It displays properly until I add in the read and write function. Then Firefox just shows a black box (no error popups).
I have done a lot of research and it seems in order to get it to work I need to have the applet signed and then it will ask the user for permission, however I also read that I can't make an applet write files and it must be server side.
So my question is can I make an applet read and write files without sever side scripting?
and if so how do I get my applet signed (I read some tutorials but I'm kinda new to this).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
已签名的小程序可以读取和写入本地计算机上的文件。
您可以使用两种类型的证书,第一种是使用 keytool(JDK 附带的应用程序)创建的证书。第二种选择是使用 Verisign 等证书颁发机构颁发的证书对小程序进行签名。
不同之处在于,自制证书将向客户端显示警告消息,指出该证书不受信任。这只是一个警告,但可能会吓到用户。来自真正的证书颁发机构的证书的缺点是它需要花钱。
要生成证书,请使用
keytool -genkey
然后进行签名,这取决于您如何构建小程序。
例如,如果您使用 Ant,则有一个 Signjar 任务将对小程序进行签名。
An applet that is signed can read and write files on the local machine.
There are two types of certificates that you can use, the first is a certificate you create with keytool, an app that comes with the JDK. The second option is to sign an applet with a certificate from a Certificate Authority like Verisign.
The difference is that the self made certificate will show warning messages to the client specifying that the certificate isn't trusted. This is just a warning, but can scare users. The downside of a certificate from a real certificate authority is that it cost money.
To generate a certificate use
keytool -genkey
then to do the signing, it depends how you build your applet.
For instance if you use Ant, there is a signjar task that will sign the applet.
当然,在 1.6.0_10+(1) JRE(“下一代”插件)中,它甚至不需要对 Jars 进行数字签名。
在下一代中使用 Java Web Start 部署的小程序。插件可以访问 JNLP API 服务。 API 的 FileContents 对象提供基本 I/O。这是一个 演示。使用 FileContents(源代码也可以在链接中找到)。
(1) 注意:从 Java 1.2 开始,JWS 可以启动自由浮动小程序。但在 1.6.0_10+ 中,JWS 小程序可以保持嵌入在浏览器窗口中(至少对于 Win 和 *nix - 我听说“没有 Mac”)。
Sure, and in a 1.6.0_10+(1) JRE (the 'Next Generation' plug-in), it does not even require the Jars to be digitally signed.
An applet deployed using Java Web Start in a next gen. plug-in has access to the JNLP API services. The FileContents object of the API provides basic I/O. Here is a demo. of using the FileContents (the source is also available at the link).
(1) Note: JWS could launch free-floating applets since Java 1.2. But with 1.6.0_10+ a JWS applet can remain embedded in a browser window (for Win. & *nix at least - I hear 'no Mac.').