Java小程序的部署工具包:如何在没有安装JVM的情况下避免重定向

Deployment Toolkit for Java applets: how to avoid the redirect when no JVM is installed

本文关键字:JVM 安装 情况下 重定向 部署 程序 工具包 Java      更新时间:2023-09-26

我已经创建了一个小程序;它是使用如下部署工具包部署的(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-如文件所述:

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

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

如果你看一下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.com进行安装。既然你有一个小程序,你就需要Java:)

或者,您可以调用deployJava.writeAppletTag(属性、参数)directy:

    /**
     * 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.
     */

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

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

您可以使用deployJava.js.

中的getJREs函数