无法在任何浏览器中打开applet

时间:2018-01-04 05:07:35

标签: java html html5 applet

我正在尝试将applet嵌入到html页面并在浏览器中查看,但我无法在任何浏览器中查看它。 (Firefox,Chrome,Edge,Internet Explorer是我检查过的浏览器,而且我在上述所有内容中都启用了java applets。)

以下是我的applet.java文件代码。

import java.applet.Applet;
 import java.awt.Graphics;

 public class MyApplet extends Applet {
     @Override
     public void paint(Graphics g) {
         g.drawString("Hello applet!", 50, 25);
     }
 }

以下是html文件的代码。

<html>
<head>
    <title>First Applet</title>
</head>
<body>
    <p>This is my first applet.</p>
        <embed code="MyApplet.class" 
            codebase="."
            type="application/x-java-applet;version=1.8">
            <noembed>
                No Java Support.
            </noembed>
        </embed>
</body></html>
  

.class文件,.java文件和.html文件都在同一个文件夹中。

1 个答案:

答案 0 :(得分:0)

Modern Browsers does not support java applets; as per below post on official Java website:

https://www.java.com/en/download/faq/chrome.xml

The Java Plugin for web browsers relies on the cross-platform plugin architecture NPAPI, which had been supported by all major web browsers for over a decade. Google's Chrome version 45 and above have dropped support for NPAPI, and therefore Java Plugin do not work on these browsers anymore.

Also, for edge, this stackover flow post indicates the same...