简体   繁体   English

尝试在浏览器上打开applet时出现错误事件

[英]Error Event when trying to open applet on a browser

I have done a few Java programs but this is the first one that I'm trying to run as an applet so I might have some basic error. 我已经完成了一些Java程序,但这是我第一个尝试作为applet运行的程序,所以我可能会遇到一些基本错误。

I compiled all the classes and put them together in a jar file called final. 我编译了所有类并将它们放在一个名为final的jar文件中。 I followed a few tutorials to make a JNLP file that I called jnlp (yeah, I know, I'm very original:) and on which I called to my jar file and I called the JNLP file from an HTML file. 我按照一些教程制作了一个JNLP文件,我称之为jnlp(是的,我知道,我非常原创:)并且我调用了我的jar文件并从HTML文件中调用了JNLP文件。

Those are the last lines of the java console output: (before them, the console is filled with my JNLP file) 这些是java控制台输出的最后几行:(在它们之前,控制台充满了我的JNLP文件)

at sun.plugin2.applet.JNLP2Manager.loadJarFiles(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
preloader: Added pending event 2: ErrorEvent[url=null label=JNLP not an applet, nor a JavaFX application cause=JNLP not an applet, nor a JavaFX application

Here is the JNLP file: 这是JNLP文件:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="jnlp.jnlp">
    <information>
        <title>Encryption Software</title>
        <vendor>Atlantis Atlantis</vendor>
        <icon href="encrypt_logo.jpg"/>
        <offline-allowed/>
    </information>
    <resources>
        <!-- Application Resources -->
        <j2se version="1.6+" href=
           "http://java.sun.com/products/autodl/j2se"/>
        <jar href="final.jar"
            main="true" />

    </resources>
    <application-desc
         name="Encryption Software"
         main-class="EncryptApplication"
         width="500"
         height="300">
     </application-desc>
     <update check="background"/>
</jnlp>

Here is the JS used to launch the applet: 这是用于启动applet的JS:

<script src="https://www.java.com/js/deployJava.js"></script>
<script>
    var attributes = {code:'', width:500, height:500};
    var parameters = {jnlp_href: 'jnlp.jnlp'};
    deployJava.runApplet(attributes, parameters, '1.6');
</script>

Is the EncryptionApplication really an applet? EncryptionApplication真的是一个applet吗? To be an applet it must extend Applet or JApplet . 要成为applet,它必须扩展AppletJApplet

If it is not an applet, it cannot be embedded in HTML. 如果它不是applet,则无法嵌入HTML中。

If it is an applet, the JNLP must declare it as such, so: 如果它 applet,JNLP必须声明它,因此:

    <application-desc
         name="Encryption Software"
         main-class="EncryptApplication"
         width="500"
         height="300">
     </application-desc>

Should be: 应该:

    <applet-desc
         name="Encryption Software"
         main-class="EncryptApplication"
         width="500"
         height="300">
     </applet-desc>

Tips 提示

  • Be sure to check the JNLP using JaNeLA . 务必使用JaNeLA检查JNLP。
  • Avoid applets like you might avoid the plague. 避免像你这样的小程序可以避免瘟疫。 They were always a complete PITA and with recent security updates, have only become more so. 它们总是一个完整的PITA,并且随着最近的安全更新,只会变得更加如此。 See Why CS teachers should stop teaching Java applets for my take on the matter. 请参阅为什么CS教师应停止教授Java applet以解决此问题。
  • It is possible to launch an application (eg a JFrame based app.) from a link using Java Web Start . 可以使用Java Web Start从链接启动应用程序 (例如,基于JFrame的应用程序)。 They will be subject to the same (very strict) security requirements of applets, but have none of the applet specific problems (see link in previous point for details). 它们将受到applet的相同(非常严格)安全要求的约束,但没有applet特定的问题(有关详细信息,请参阅前一点中的链接)。
  • As mentioned by @ElliottFrisch, it is best to include a valid value for the code attribute. 正如@ElliottFrisch所提到的,最好包含code属性的有效值。 There are circumstances in which it can be left out, but I won't get into that right now.. 某些情况下,它可以被排除在外,但我现在不会进入那个......

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

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