Autodownload for Conventional Applets


This section covers the following topics:

The Autodownload Script

After you have written your applet and are ready to publish it to the web for the world to use, you want to ensure that users of your applet have the latest JRE/Java Plug-in. Previous releases of the Java Plug-in allowed you to provide for autodownload of the appropriate JRE by replacing APPLET tags with OBJECT tags in your applet's HTML page. Now that Java Plug-in supports the APPLET tag, there is no longer a need to use OBJECT tags in your applet's HTML page, and Sun therefore provides an alternative means to enable autodownload that doesn't depend on OBJECT tags.

Sun provides a script, autodownload.js, that you may invoke from your applet's web page to enable autodownload of JRE/Java Plug-in. This script is available on Sun's web site at http://java.sun.com/browser/autodownload.js. You may copy this file to your server for local reference by your web pages, if you desire. To enable autodownload of the JRE/Java Plug-in, place an invocation of the autodownload.js script in the head of your applet's web page, as in this example:

<HEAD>
   <TITLE>....</TITLE>
   <SCRIPT language="VBSCRIPT" src="http://java.sun.com/browser/autodownload.js">
   </SCRIPT>
</HEAD>

If you choose to host the autodownload.js script on your own server, the src attribute would be set to the local path to the script on your web site.

When your applet's web page is accessed by a user, the script will perform the following checks.

If the user's machine already has correct version of JRE/Java Plug-in, the script's job is done and your applet will be launched using that JRE/Java Plug-in. If the script instead determines that the user does not have the correct version of JRE/Java Plug-in, the script will present the user with a dialog window, similar to the following, asking the user confirm that he or she wants to download Sun's runtime environment.

If the user selects "No," the script terminates and any APPLET tags in your web page will be handled by the browser's internal runtime environment. If the user selects "Yes," the script will connect to a servlet, described in the next section, on the Sun web site.

The Download Servlet

The servlet is located http://java.sun.com/browser/download.html, and it determines whether the user has a Microsoft Windows platform and Internet Explorer installed. If not, the servlet opens the manual download page for the Java 2 Runtime Environment (http://java.sun.com/j2se/1.4/jre/).

If the user does have Internet Explorer on Microsoft Windows, then the servlet will send the user to http://java.sun.com/browser/download.html. This web page invokes an applet by using an OBJECT tag that has the effect of initiating the autodownload of the latest JRE/Java Plug-in to the user's machine.

When the download of JRE/Java Plug-in finishes, the installation wizard will start to guide the user through installation.

When JRE/Java Plug-in has been installed on the user's machine, the applet on http://java.sun.com/browser/download.html will begin to run. When the user closes that applet's window, your applet will load and run in the user's browser.

Linking to the Download Servlet

In addition to, or instead of, using the autodownload script in your applet's web page as described above, you may also provide links to the download servlet directly from your web site. You may provide the link in the form of this "Get Java Now" image:

 

The Sun web site displays this image with a link to the download servlet in several prominent places such as the Java Software home page, and you are encouraged to use it to link to the servlet from your web site also.

The URL of the download servlet is http://dlres.java.sun.com/PluginBrowserCheck, so the HTML you would add to your web site would look something like this:

<a href="http://dlres.java.sun.com/PluginBrowserCheck">
<img src="GetJavaNow.gif" alt="Get Java Now" border="0">
</a>