Java Web Start开发指南(二)
添加时间: 2006-2-19 6:10:29 作者: JAVA教程 阅读次数:296 来源: http://www.d9soft.com
Java Web Start 充分利用了已经存在的Internet技术,例如HTTP协议和Web服务器,这使得已存在的
用于部署基于HTML内容的基础系统能够重用来使用Java Web Start部署基于Java技术的应用程序。
为了在客户机上部署你的应用,你必须确保包含应用程序的所有文件能够通过Web服务器进行访问。
这意味着你必须拷贝一个或者多个与JNLP文件相一致的jar文件到你的Web服务器目录中。使Web站点
支持Java Web Start的设置类似于部署基于HTML的内容文件。唯一需要注意的是为Web服务器呗指一
种新的MIME类型。
1、配置Web服务器使之使用Java Web Start MIME类型
配置Web服务器,使所有的以.jnlp为扩展名的文件设置为application/x-java-jnlp-file MIME 类型
。
多数Web浏览器根据从Web服务器返回内容的MIME类型来决定怎样去处理特定的内容。为了让Web浏览
器调用Java Web Start,必须让服务器对jnlp文件返回application/x-java-jnlp-file MIME 类型。
每个Web服务器都有增加MIME类型的方法。对于Apache Web 服务器,必须增加以下行到.mime.types
配置文件中:
application/x-java-jnlp-file JNLP
对于器她服务器,请核对相关文档。
2、给应用程序建立一个JNLP文件
建立JNLP文件的简便方法是根据你的要求修改已经存在的JNLP文件。
在后面相关部分将会谈到JNLP文件的语法与格式。
3、确保应用程序能够通过Web服务器进行访问
确保你的应用程序的JAR文件和JNLP文件能够用JNLP文件中列出的URL进行访问。
4、在网页上建立一个指向JNLP文件的超级连接。
指向JNLP文件的超级连接是一个标准的HTML连接。例如:
Launch My Application
按照第一步中的设置所述,Web服务器将对所有以.jnlp为扩展名的任何文件自动返回
application/x-java-jnlp-file MIME 类型。这是确保Web浏览器在下载此文件的时候启动Java Web
Start的前提条件。
还应该在网页上提供一个Java Web Start安装程序的链接,这样将使那些还没有安装Java Web Start
的用户能够下载和安装Java Web Start。
对Java Web Start是否安装的检测:
在HTML页面中使用JavaScript/VBScript可以检测Java Web Start是否安装。示例如下:
注意这里的JavaScript脚本不能对Gecko-based的浏览器(例如:Netscape 6.x)是否安装Java Web
Start进行检测。
insertLink方法检测Java Web Start是否安装。如果已经安装的话,此方法输出的HTML将类似于:
My Application
如果没有安装的话将输出:
Need to install Java Web Start
在实际使用中,这应该是指向一个下载页面的链接。
示例JavaScript/VBScript如下:
以上的示例脚本调用浏览器检测脚本xbDetectBrowser.js。xbDetectBrowser.js的内容如下:
/* ***** BEGIN LICENSE BLOCK *****
* Licensed under Version: MPL 1.1/GPL 2.0/LGPL 2.1
* Full Terms at http://devedge.netscape.com/lib/js/license/mpl-tri-license.txt
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Netscape code.
*
* The Initial Developer of the Original Code is
* Netscape Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Bob Clary
*
* ***** END LICENSE BLOCK ***** */
function xbDetectBrowser()
{
var oldOnError = window.onerror;
var element = null;
window.onerror = null;
// work around bug in xpcdom Mozilla 0.9.1
window.saveNavigator = window.navigator;
navigator.OS = '';
navigator.version = parseFloat(navigator.appVersion);
navigator.org = '';
navigator.family = '';
var platform;
if (typeof(window.navigator.platform) != 'undefined')
{
platform = window.navigator.platform.toLowerCase();
if (platform.indexOf('win') != -1)
navigator.OS = 'win';
else if (platform.indexOf('mac') != -1)
navigator.OS = 'mac';
else if (platform.indexOf('unix') != -1 platform.indexOf('linux') != -1
platform.indexOf('sun') != -1)
navigator.OS = 'nix';
}
var i = 0;
var ua = window.navigator.userAgent.toLowerCase();
if (ua.indexOf('opera') != -1)
{
i = ua.indexOf('opera');
navigator.family = 'opera';
navigator.org = 'opera';
navigator.version = parseFloat('0' + ua.substr(i+6), 10);
}
else if ((i = ua.indexOf('msie')) != -1)
{
navigator.org = 'microsoft';
navigator.version = parseFloat('0' + ua.substr(i+5), 10);
if (navigator.version < 4)
navigator.family = 'ie3';
else
navigator.family = 'ie4'
}
else if (ua.indexOf('gecko') != -1)
{
navigator.family = 'gecko';
var rvStart = ua.indexOf('rv:');
var rvEnd = ua.indexOf(')', rvStart);
var rv = ua.substring(rvStart+3, rvEnd);
var rvParts = rv.split('.');
var rvValue = 0;
var exp = 1;
for (var i = 0; i < rvParts.length; i++)
{
var val = parseInt(rvParts[i]);
rvValue += val / exp;
exp *= 100;
}
navigator.version = rvValue;
if (ua.indexOf('netscape') != -1)
navigator.org = 'netscape';
else if (ua.indexOf('compuserve') != -1)
navigator.org = 'compuserve';
else
navigator.org = 'mozilla';
}
else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) &&
(ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&&
(ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
{
var is_major = parseFloat(navigator.appVersion);
if (is_major < 4)
navigator.version = is_major;
else
{
i = ua.lastIndexOf('/')
navigator.version = parseFloat('0' + ua.substr(i+1), 10);
}
navigator.org = 'netscape';
navigator.family = 'nn' + parseInt(navigator.appVersion);
}
else if ((i = ua.indexOf('aol')) != -1 )
{
// aol
navigator.family = 'aol';
navigator.org = 'aol';
navigator.version = parseFloat('0' + ua.substr(i+4), 10);
}
else if ((i = ua.indexOf('hotjava')) != -1 )
{
// hotjava
navigator.family = 'hotjava';
navigator.org = 'sun';
navigator.version = parseFloat(navigator.appVersion);
}
window.onerror = oldOnError;
}
xbDetectBrowser();
PS:我只是提供以上的文章供大家参考,希望对大家有帮助,有共同爱好的朋友到www.redsec.org的论坛与我联系
上下文章:
上一篇文章: Java Web Start 开发指南(三) 下一篇文章: Java Web Start开发指南(一)
相关文章:

