简体   繁体   English

从访客计算机上的网页运行 java class 文件?

[英]Run a java class file from a webpage on the visitor computer?

I coded a Java program to read and modify a file on the computer.我编写了一个 Java 程序来读取和修改计算机上的文件。 The program is based only on 1 class.该程序仅基于 1 class。

At the moment who want to use it has to run it from terminal, I'm looking on how to insert it on a webpage and make it run on the visitor's computer.目前想要使用它的人必须从终端运行它,我正在研究如何将它插入网页并使其在访问者的计算机上运行。 It would be fine to have a file chooser (the user will want this modification).有一个文件选择器就好了(用户会想要这个修改)。

I searched on inte.net and found Java applets, but I read that they aren't downloaded and executed locally so the program won't work.我在 inte.net 上搜索并找到了 Java 个小程序,但我读到它们没有在本地下载和执行,因此程序无法运行。

How to provide a Java class file from a webpage, for use on the computer of the end-user?如何从网页提供 Java class 文件,供最终用户的计算机使用?

If you really want to download a Java program and run it locally, you should check out Java Web Start .如果你真的想下载一个 Java 程序并在本地运行,你应该查看Java Web 开始

Briefly, it allows the user to download and run a Java program locally on their machine.简而言之,它允许用户在他们的机器上本地下载并运行 Java 程序。 It does clever stuff like identify if an updated version is available for download, and will run the cached version if that's the current version.它会做一些聪明的事情,比如确定是否有更新版本可供下载,如果是当前版本就会运行缓存的版本。

Here's a tutorial .这是一个教程

Applets can modify files locally, if they are signed and the user allows them to.小应用程序可以在本地修改文件,如果它们被签名并且用户允许的话。

Read up on signed applets.阅读已签名的小程序。

..it would be fine to have a file chooser.. ..有一个文件选择器就好了..

In that case, there are basically the two options as I've outlined in comments throughout this question & the answers.在那种情况下,基本上有两个选项,正如我在整个问题和答案的评论中概述的那样。 I'll collect them together here:我会在这里收集它们:

  1. Digitally sign the applet, get the user to accept the digitally signed code when prompted (before the applet is loaded), then offer a JFileChooser to browse to the file.对 applet 进行数字签名,在出现提示时(在加载 applet 之前)让用户接受数字签名代码,然后提供JFileChooser以浏览文件。
  2. If the user has a plugin 2 JRE (chase the links in the JWS info. page for more details), it is possible to deliver the applet to the user unprompted, then leverage the JNLP API to produce a file chooser.如果用户有一个插件 2 JRE(查看JWS 信息页面中的链接以获取更多详细信息),则可以自动将小程序交付给用户,然后利用 JNLP API 生成文件选择器。 The user will be prompted before the dialog appears, this time with a more specific warning.在对话框出现之前会提示用户,这次会发出更具体的警告。

JWS JWS

  • For an example, see my applet based GIF animation tool which uses the JNLP API when the user goes to load image frames or save the animated GIF.例如,请参阅我的基于小程序的GIF animation 工具,该工具在用户加载图像帧或保存动画 GIF 时使用 JNLP API。
  • That applet is not open source (mostly because of my laziness in not wanting to revisit & tidy the code) but there is a much better example of using the JNLP file services that comes complete with source.那个小程序不是开源的(主要是因为我不想重新访问和整理代码的懒惰)但是有一个更好的例子使用源代码附带的 JNLP 文件服务

Digital signatures数字签名

I don't have any great links about the process of digitally signing code, but note that the 'example of using the JNLP file services' listed above provides one set of signed Jars for 2 different security environments.我没有关于代码数字签名过程的任何重要链接,但请注意,上面列出的“使用 JNLP 文件服务的示例”为 2 个不同的安全环境提供了一组已签名的 Jars。 It also (hopefully obviously) demonstrates how to digitally sign code using Ant (it all happens by invoking the default task in the build.xml ).它还(希望很明显)演示了如何使用 Ant 对代码进行数字签名(这一切都是通过调用build.xml中的默认任务实现的)。

I read that they aren't downloaded and excuted locally我读到它们不是在本地下载和执行的

Whereever you read that, it is 100% incorrect.无论你在哪里读到它,它都是 100% 不正确的。 Applets are downloaded into the browser and executed at the client host.小程序被下载到浏览器中并在客户端主机上执行。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM