Creating the Web Page That Launches the Application



This chapter includes the following topics:

Introduction

In order for an application to be launched from a web page via JNLP, the page must include a link to the JNLP file. E.g., to be able to launch application app.jnlp on a web site http://www.yyy.zzz, the page needs to include the following link:

<a href=http://www.yyy.zzz/app.jnlp>Launch the application</a>

It may be the case, however, that JAWS is not installed on the user's computer. Thus the page needs to include logic (scripts) to take account of this. In fact, the page should include logic for the following:

Detect if Java Web Start (JAWS) is installed

The scripts, and the HTML for the auto-install page, are discussed below.

Detecting if JAWS is installed on Netscape

Here is the first script that should be run on a web page for launching an application via JNLP:

<SCRIPT LANGUAGE="JavaScript"> 
var javawsInstalled = 0;
var javaws12Installed = 0; var javaws142Installed=0;
isIE = "false";
if (navigator.mimeTypes && navigator.mimeTypes.length) {
x = navigator.mimeTypes['application/x-java-jnlp-file'];
if (x) { javawsInstalled = 1; javaws12Installed=1;
javaws142Installed=1;
}
}
else {
isIE = "true";
}
</SCRIPT>

This script looks at the navigator.mimeTypes object and the navigator.mimeTypes.length var to decide if the browser is Netscape or IE. If length is 0, it is assumed the browser is IE, as with IE the navigator.mimeTypes array is defined but always empty. If length is non-zero, then the browser is assumed to be Netscape and the JNLP MIME type is checked to see if it exists on Netscape. If so, javawsInstalled, javaws12Installed, and javaws142Installed are all set to 1. With Netscape it is not possible to determine which particular version of JAWS is installed, so all three variables are set to 1.

Detecting if JavaWeb Start is installed on IE, and if so, the version

The above JavaScript should be followed by a VBScript that sets variables related to Internet Explorer browers:

<SCRIPT LANGUAGE="VBScript">
on error resume next
If isIE = "true" Then
  If Not(IsObject(CreateObject("JavaWebStart.isInstalled"))) Then
     javawsInstalled = 0
  Else
     javawsInstalled = 1
  End If
  If Not(IsObject(CreateObject("JavaWebStart.isInstalled.2"))) Then
     javaws12Installed = 0
  Else
     javaws12Installed = 1
  End If
  If Not(IsObject(CreateObject("JavaWebStart.isInstalled.1.4.2.0"))) Then
     javaws142Installed = 0
  Else
     javaws142Installed = 1
  End If  
End If
</SCRIPT>

This VBScript is executed if the variable isIE from the preceeding JavaScript is "true"; i.e., if the end-user's browser is Internet Explorer. This script instantiates the isInstalled COM object in JavaWebStart.dll, and this object determines two things:

After the above two scripts have been executed, the variables javawsInstalled, javaws12Installed, and javaws142Installed will be set to either 1 or 0, as follows:

Browser
javawsInstalled javaws12Installed javaws142Installed
Internet Explorer 1 if any version of JAWS is installed; 0 otherwise. 1 if JAWS 1.2 is installed; 0 otherwise. 1 if JAWS 1.4.2 is installed; 0 otherwise.
Netscape Navigator 1 if any version of JAWS is installed; 0 otherwise. 1 if any version of JAWS is installed; 0 otherwise. 1 if any version of JAWS is installed; 0 otherwise.

Launching the application if JAWS is Installed—or providing a link for auto-install or general download page

An additional JavaScript can be used to decide whether to:

The following JavaScript handles these scenarios:

<SCRIPT LANGUAGE="JavaScript">
/* Note that the logic below always launches the JNLP application
*if the browser is Gecko based. This is because it is not possible
*to detect MIME type application/x-java-jnlp-file on Gecko-based browsers.
*/ if (javawsInstalled || (navigator.userAgent.indexOf("Gecko") !=-1)) { document.write("<a href=http://www.yyy.zzz/app.jnlp>Launch the application</a>"); } else { document.write("Click "); document.write("<a href=http://java.sun.com/PluginBrowserCheck? pass=http://www.yyy.zzz/download.html& fail=http://java.sun.com/j2se/1.4.2/download.html>here</a> "); document.write("to download and install JRE 1.4.2 and the application."); } </SCRIPT>

Notes:

  1. The script only uses javawsInstalled, not javaws12Installed or javaws142Installed.
  2. The line breaks following '?' and '&' are for readability purposes only; in an actual script there should be no breaks in the href string.

If javawsInstalled is 1, indicating that JAWS is already available on the client, then the script provides a link to the application's jnlp file. If JAWS is not installed on the client, the script instead provides a link to the PluginBrowserCheck program on the java.sun.com web site. PluginBrowserCheck checks whether the client uses Internet Explorer on a Microsoft Windows platform. If so, PluginBrowserCheck sends the user to the auto-install page http://www.yyy.zzz/download.html. (See the next section, Creating an auto-install page, for how to create an auto-install page for IE running on Windows.) If PluginBrowserCheck determines the user is not using Internet Explorer on Microsoft Windows, the user is redirected to the 1.4.2 JRE general download page on java.sun.com.

Creating an auto-install page

Note:

For a complete list of JRE releases that can be autodownloaded via a .cab file, as mentioned below, see Autodownload Files (Windows Only).

The download.html file should be staged on the server side. It contains special OBJECT and PARAM tags that will download to the client an auto-installer for J2RE 1.4.2. Along with JAWS, an ActiveX control will be downloaded to the client. The ActiveX control will launch the application using the newly installed JAWS. Here is a sample download.html file:

<HTML>
<BODY>
<OBJECT CODEBASE="http://java.sun.com/products/plugin/autodl/jinstall-1_4_2-windows-i586.cab" 
CLASSID="clsid:5852F5ED-8BF4-11D4-A245-0080C6F74284" HEIGHT=0 WIDTH=0>
<PARAM NAME="app" VALUE="http://www.yyy.zzz/app.jnlp">
<PARAM NAME="back" VALUE="true">
<!-- Alternate HTML for browsers which cannot instantiate the object -->
<A HREF="http://java.sun.com/j2se/1.4.2/download.html">
Download Java Web Start</A>
</OBJECT>
</BODY>
</HTML>

This OBJECT tag fetches a .cab file that contains an auto-installer for JRE 1.4.2. (Note that this .cab file will not be available until the GA release of the 1.4.2 SDK/JRE.) The PARAM tags specify the location of the application's jnlp file so that it may be automatically launched after the JRE is installed on the client.