简体   繁体   中英

How to add Java Applet to HTML file?

I have made and compiled a Java applet and run it using 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. I have viewed lots of pages and forums with people facing the same problem with no use. My html code is:

`<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. Thank you in advance!!

tl;dr

Wrap your Java applet in a JNLP file to be served as a Java Web Start app.

Oracle no longer supports Java Applet technology

Oracle officially deprecated the Applet API in JEP 289 for Java 9 . The appletviewer tool is also deprecated. These are not marked for deletion in the next version after Java 9, but may go away in later versions.

Browsers no longer support Java Applet

Embedding Java Applets within web browsers has proven to be an insoluble security problem. The industry has given up on trying to make this work. Ditto for Flash and Silverlight .

Google Chrome browser no longer supports the NPAPI plugin architecture , and therefore no longer supports Java Applet technology.

Microsoft Edge web browser does not support plugins such as that needed for Java Applet.

Mozilla Firefox browser dropped support for the NPAPI plugin architecture, and therefore Java Applet, in version 52 and later. See this Question on SuperUser.StackExchange.com . For older versions, Mozilla gives instructions on how to disable Java Applet .

Apple has been taking steps to phase out Java Applet support for years. 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 .

And speaking of Microsoft Internet Explorer browsers, you might be able to get Java Applet to work. Try these instructions . I do not recommend doing so.

Java Web Start

I do not recommend using Java Applets.

Instead, learn about Java Web Start technology. 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.

For security, they run by default in the same kind of limited “sandbox” as Java Applets. 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.

Oracle and the Java community continue to actively support and advance Java Web Start, including an update to the JNLP spec in 2017-09.

Your code is okay the problem is on he browser. Most browsers now days are ending support for java. Browsers don't allow and don't support java code to run, like running applets on the browser. The good old days of java code on browser has come to an end. Newer version and updates of HTML are killing java same they did with flashplayer. Maybe Internet Explorer might be a good option in this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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