【问题标题】:Deployment Toolkit for Java applets: how to avoid the redirect when no JVM is installedDeployment Toolkit for Java applet:未安装 JVM 时如何避免重定向
【发布时间】:2013-01-30 06:33:16
【问题描述】:

我创建了一个小程序;它使用Deployment Toolkit 进行部署,如下所示(URL 是假的):

<script type="text/javascript" 
             src="https://www.java.com/js/deployJava.js"></script>
<script>
var attributes = {
        code:'br.com.brandizzi.adam.applet.MyApplet.class',
        archive:'http://adam.brandizzi.com.br/html/applet.jar',
        width : 50,
        height : 1
    };
    var parameters = {
        fontSize : 1,
    };
    var version = '1.6';
    deployJava.runApplet(attributes, parameters, version);
</script>

效果很好。然而幸运的是,我通过一台没有 JVM 的机器访问了我的站点,并且它总是被重定向到 http://www.java.com - as the documentation states

如果客户端没有所需的最低 JRE 软件版本,部署工具包脚本会将浏览器重定向到http://www.java.com,以允许用户下载最新的 JRE 软件。在某些平台上,用户可能会在查看包含小程序的网页之前被重定向。

有没有办法避免这种重定向?该页面可以在没有 JVM 的情况下运行良好,小程序只是一点点改进。无论如何,我们的用户可能会对这种重定向感到非常困惑,他们甚至没有安装 JVM 的权限。

【问题讨论】:

    标签: java javascript applet jnlp java-deployment-toolkit


    【解决方案1】:

    使用 Deployment Toolkit 的全部意义在于,如果用户没有 JVM,它会提示用户安装 JVM,以便您的小程序可以运行。如果您不希望它们被提示,那么就不要使用部署工具包。

    如果他们已经安装了合适的 JVM,那么您的小程序将运行。如果没有,页面的其余部分应该正常加载。

    【讨论】:

    • 这很公平,但是在没有任何信息的情况下将用户重定向到另一个页面是不明智的。另外,我试图避免使用 标记,但它被认为已弃用。无论如何,我很惊讶部署工具包没有这么简单的选项...
    • @brandizzi 选项是“一开始就不要使用工具包”。另外,它是一个单独的JS文件,应该可以对其进行monkeypatch。
    • 部署工具包没有做任何神奇的事情。注释代码可在 java.com/js/deployJava.txt 获得,因此如果您想更改行为,请将副本保存到您的网站,例如 adam.brandizzi.com.br/html/myDeployJava.js,将 html 中的脚本标记更改为指向它而不是 java.com/js/deployJava.js 并更改行为。然而,如果你看看 deployJava.js 做了什么,如果用户安装了 JVM,它实际上会插入一个 标签,所以它不是“避免使用 标签”。
    【解决方案2】:

    如果你看一下 deployJava.js 脚本并且 runApplet 函数是这样说的:

         /**
         * Ensures that an appropriate JRE is installed and then runs an applet.
         * minimumVersion is of the form #[.#[.#[_#]]], and is the minimum
         * JRE version necessary to run this applet.  minimumVersion is optional,
         * defaulting to the value "1.1" (which matches any JRE).
         * If an equal or greater JRE is detected, runApplet() will call
         * writeAppletTag(attributes, parameters) to output the applet tag,
         * otherwise it will call installJRE(minimumVersion + '+').
    

    所以如果你这样打电话

    deployJava.runApplet(attributes, parameters, null);
    

    或者像这样

    deployJava.runApplet(attributes, parameters, 'undefined');
    

    或者像这样

    deployJava.runApplet(attributes, parameters, '1.1');
    

    它只会检查是否安装了 Java,然后才会重定向到 java.com 进行安装。既然你有一个小程序,你确实需要 Java :)

    您也可以直接调用 deployJava.writeAppletTag(attributes, parameters)

        /**
         * Outputs an applet tag with the specified attributes and parameters, where
         * both attributes and parameters are associative arrays.  Each key/value
         * pair in attributes becomes an attribute of the applet tag itself, while
         * key/value pairs in parameters become <PARAM> tags.  No version checking
         * or other special behaviors are performed; the tag is simply written to
         * the page using document.writeln().
         *
         * As document.writeln() is generally only safe to use while the page is
         * being rendered, you should never call this function after the page
         * has been completed.
         */
    

    【讨论】:

    • “既然你有一个applet,你就需要Java”是不正确的,因为他写道:“页面没有JVM也可以很好地工作,applet只是一点点改进”。
    • 完整版在哪里?我只看到一个最小化的版本
    【解决方案3】:

    您可以使用deployJava.js 中的getJREs 函数。

    【讨论】:

      猜你喜欢
      • 2014-07-21
      • 1970-01-01
      • 2018-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      • 2011-11-24
      • 2012-12-01
      相关资源
      最近更新 更多