简体   繁体   English

如何将 Java Applet 添加到 HTML 文件?

[英]How to add Java Applet to HTML file?

I have made and compiled a Java applet and run it using java appletviewer.我已经制作并编译了一个 Java 小程序,并使用 java appletviewer 运行它。 It is running fine as expected.它按预期运行良好。 But I am not able to run it usingany web browser like chrome or internet explorer even after enabling java.但是,即使启用了 java,我也无法使用任何网络浏览器(如 chrome 或 Internet Explorer)运行它。 I have viewed lots of pages and forums with people facing the same problem with no use.我查看了很多页面和论坛,人们都面临同样的问题,但没有用。 My html code is:我的html代码是:

`<html>
<head>
<title> Calculator </title>
<!--<meta name="discription" content="MultiPurpose Calculator">
<meta name="keywords" content="standard calculator;scientific calculator;loan calculator;calculator;applet">-->
</head>
<Applet code="cal3.class" width=500 height=600>
</Applet>
</html>`

cal3 is the name of the compiled java class. cal3 是已编译的 java 类的名称。 Thank you in advance!!先感谢您!!

tl;dr tl;博士

Wrap your Java applet in a JNLP file to be served as a Java Web Start app.将您的 Java 小程序包装在 JNLP 文件中以用作Java Web Start应用程序。

Oracle no longer supports Java Applet technology Oracle 不再支持 Java Applet 技术

Oracle officially deprecated the Applet API in JEP 289 for Java 9 . Oracle 在JEP 289 for Java 9 中正式弃用 Applet API。 The appletviewer tool is also deprecated. appletviewer工具也已弃用。 These are not marked for deletion in the next version after Java 9, but may go away in later versions.这些在 Java 9 之后的下一个版本中不会被标记为删除,但可能会在以后的版本中消失。

Browsers no longer support Java Applet浏览器不再支持 Java Applet

Embedding Java Applets within web browsers has proven to be an insoluble security problem.在 Web 浏览器中嵌入 Java Applet 已被证明是一个无法解决的安全问题。 The industry has given up on trying to make this work.该行业已放弃尝试进行这项工作。 Ditto for Flash and Silverlight . FlashSilverlight同上。

Google Chrome browser no longer supports the NPAPI plugin architecture , and therefore no longer supports Java Applet technology. Google Chrome 浏览器不再支持NPAPI 插件架构,因此不再支持 Java Applet 技术。

Microsoft Edge web browser does not support plugins such as that needed for Java Applet. Microsoft Edge Web 浏览器不支持 Java Applet 所需的插件。

Mozilla Firefox browser dropped support for the NPAPI plugin architecture, and therefore Java Applet, in version 52 and later. Mozilla Firefox 浏览器在版本 52 及更高版本中放弃了对 NPAPI 插件架构的支持,因此也不再支持 Java Applet。 See this Question on SuperUser.StackExchange.com .请参阅SuperUser.StackExchange.com 上的这个问题 For older versions, Mozilla gives instructions on how to disable Java Applet .对于旧版本,Mozilla 提供了有关如何禁用 Java Applet 的说明

Apple has been taking steps to phase out Java Applet support for years.多年来,Apple 一直在采取措施逐步淘汰 Java Applet 支持。 This includes giving directions to disable the necessary plugin , as well as defaulting to disabling, and later omitting, the necessary plugin.这包括给出禁用必要插件的指示,以及默认禁用和稍后省略必要插件。 Now Safari 11 has no direct support, though you might get it to work by mimicking a Microsoft Internet Explorer browser as described here .现在 Safari 11 没有直接支持,但您可以通过模仿此处所述的 Microsoft Internet Explorer 浏览器来使其工作。

And speaking of Microsoft Internet Explorer browsers, you might be able to get Java Applet to work.说到 Microsoft Internet Explorer 浏览器,您也许可以让 Java Applet 工作。 Try these instructions .试试这些说明 I do not recommend doing so.我不建议这样做。

Java Web Start Java Web 入门

I do not recommend using Java Applets.我不推荐使用 Java Applet。

Instead, learn about Java Web Start technology.相反,学习Java Web Start技术。 You get the convenience of obtaining and launching Java apps via the web browser, but the actual app runs as a separate local app on the user's machine rather than inside the browser.您可以方便地通过 Web 浏览器获取和启动 Java 应用程序,但实际应用程序在用户计算机上作为单独的本地应用程序运行,而不是在浏览器内运行。

For security, they run by default in the same kind of limited “sandbox” as Java Applets.为了安全起见,它们默认在与 Java Applet 相同的有限“沙箱”中运行。 This sandbox restricts access to the various features of the host OS and hardware.此沙箱限制对主机操作系统和硬件的各种功能的访问。 You can take measures to relax the security restrictions, as appropriate to the needs of your app.您可以根据您的应用程序的需要采取措施放宽安全限制。

Wrap your applet包裹你的小程序

You can even wrap an existing Java Applet in a jar file with a JNLP file to deploy as a Java Web Start app.您甚至可以使用JNLP 文件将现有 Java Applet 包装在 jar 文件中,以部署为 Java Web Start 应用程序。

Oracle and the Java community continue to actively support and advance Java Web Start, including an update to the JNLP spec in 2017-09. Oracle 和 Java 社区继续积极支持和推进 Java Web Start,包括在 2017 年 9 月更新JNLP 规范

Your code is okay the problem is on he browser.您的代码没问题,问题出在浏览器上。 Most browsers now days are ending support for java.现在大多数浏览器都结束了对 java 的支持。 Browsers don't allow and don't support java code to run, like running applets on the browser.浏览器不允许也不支持运行 java 代码,比如在浏览器上运行小程序。 The good old days of java code on browser has come to an end.浏览器上 Java 代码的美好时光已经结束。 Newer version and updates of HTML are killing java same they did with flashplayer. HTML 的较新版本和更新正在杀死 Java,就像他们使用 flashplayer 所做的一样。 Maybe Internet Explorer might be a good option in this case.在这种情况下,Internet Explorer 可能是一个不错的选择。

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

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