This chapter includes the following topics:
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.MySite.com
, the page needs to include the
following link:
<a href=http://www.MySite.com/app.jnlp>Launch
the application</a>
It may be the case, however, that Java Web Start 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 is installed
If so, launch the application.
If not, detect if user is running IE on Window.
If so, provide link to a page that can auto-install the JRE for Windows
If not, provide a link to the general download page for the JDK/JRE.
The scripts, and the HTML for the auto-install page, are discussed below.
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 javaws142Installed=0; var javaws150Installed=0; var javaws160Installed = 0; isIE = "false"; if (navigator.mimeTypes && navigator.mimeTypes.length) { x = navigator.mimeTypes['application/x-java-jnlp-file']; if (x) { javawsInstalled = 1; javaws142Installed=1; javaws150Installed=1; javaws160Installed = 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
,
javaws142Installed
, javaws150Installed
and
javaws160Installed
are all set to 1. With Netscape it is
not possible to determine which particular version of Java Web Start
is installed, so all four variables are set to 1.
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.1.4.2.0"))) Then javaws142Installed = 0 Else javaws142Installed = 1 End If If Not(IsObject(CreateObject("JavaWebStart.isInstalled.1.5.0.0"))) Then javaws150Installed = 0 Else javaws150Installed = 1 End If If Not(IsObject(CreateObject("JavaWebStart.isInstalled.1.6.0.0"))) Then javaws160Installed = 0 Else javaws160Installed = 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 four things:
whether the client machine has any version of Java Web Start installed;
whether the client machine has version 1.2 of Java Web Start installed;
whether the client machine has versions 1.4.2 of Java Web Start installed;
whether the client machine has versions 1.5.0 of Java Web Start installed.
whether the client machine has versions 1.6.0 of Java Web Start installed.
After the above two scripts have been executed, the variables
javawsInstalled, javaws142Installed
,
javawsInstalled150
and javawsInstalled160
will be set to either 1 or 0, as follows:
Browser |
|
|
|
|
---|---|---|---|---|
Internet Explorer |
1 if any version of Java Web Start is installed; 0 otherwise. |
1 if Java Web Start 1.4.2 is installed; 0 otherwise. |
1 if Java Web Start 1.5.0 is installed; 0 otherwise. |
1 if Java Web Start 1.6.0 is installed; 0 otherwise. |
Netscape Navigator |
1 if any version of Java Web Start is installed; 0 otherwise. |
1 if any version of Java Web Start is installed; 0 otherwise. |
1 if any version of Java Web Start is installed; 0 otherwise. |
1 if any version of Java Web Start is installed; 0 otherwise. |
An additional JavaScript can be used to decide whether to:
provide a link to the application's jnlp file (i.e., Java Web Start is installed);
initiate auto-download of JRE 6.0, which includes Java Web Start (i.e., Java Web Start is not installed and the user is running IE on Windows);
or provide a link to the general download page for the 6.0 JDK/JRE (i.e., Java Web Start is not installed and the user is not running IE on Windows).
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.MySite.com/app.jnlp>Launch the application</a>"); } else { document.write("Click "); document.write("<a href=http://java.sun.com/PluginBrowserCheck? pass=http://www.MySite.com/download.html& fail=http://java.sun.com/javase/downloads/ea.jsp>here</a> "); document.write("to download and install JRE 5.0 and the application."); } </SCRIPT>
Notes:
|
If javawsInstalled is 1, indicating that Java Web Start
is already available on the client, then the script provides a link
to the application's jnlp
file. If Java Web Start 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.MySite.com/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
6.0 JRE general download page on java.sun.com
.
Note: The For a complete list of JRE releases that can be autodownloaded
via a |
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 JRE 6.0 . Along with Java Web Start, an ActiveX control will be downloaded to the client. The ActiveX control will launch the application using the newly installed Java Web Start. Here is a sample download.html file:
<HTML> <BODY> <OBJECT codebase="http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab#Version=6,0,0,0" classid="clsid:5852F5ED-8BF4-11D4-A245-0080C6F74284" height=0 width=0> <PARAM name="app" value="http://www.MySite.com/app.jnlp"> <PARAM name="back" value="true"> <!-- Alternate HTML for browsers which cannot instantiate the object --> <A href="http://java.sun.com/javase/downloads/ea.jsp"> Download Java Web Start</A> </OBJECT> </BODY> </HTML>
The OBJECT tag fetches a .cab
file that
contains an auto-installer for JRE 6.0.
The URL: http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab will return the latest update release available for the Java SE 6 release.
The string: Version=6,0,0,0 will be used to compare with the wsdetect.dll version, which is registered with the CLSID above. If the local machine has the dll installed and the version is greater than or equal to the Version specified, we will just load the dll in the local machine. Otherwise it will download and install Java from the codebase specified.
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.
app
:
Once the Java Web Start Active-X control is installed/loaded, it will
invoke Java Web Start to launch the application specified by this
URL.
back
:
This controls the behavior of the browser after launching the
application. It can remain on the current page (download.html in this
case) or navigate back to the previous page.
For issues relating to application development see the next chapter, Application Development Considerations.