我第一次不得不在这里问一个问题,因为我总是能找到答案。我不知道Java或.jnlp文件是如何工作的。
项目上下文
我的网站上有一个网页,当人们点击下载一个文件时,它会加载一个空白的页面。然后,此空白页加载.jnlp文件,当用户启动该文件时,该文件将执行java代码。不幸的是,许多用户很难理解正在发生的事情。我的任务是把这个下载包在我们的Magento系统中,并添加指令,让人们知道他们在哪里。
问题
一切都像预想的那样运转。唯一的例外是,.jnlp文件在启动时显示一个“无法启动应用程序”的错误。问题是,整个网站的内容被写入文件,这导致它失败。我找到的唯一解决办法是在一个新的空白.jnlp文件中启动window....which,这违背了我所要做的工作的目的。
问题
是否有一种方法可以在页面上启动.jnlp文件,而不必打开新的选项卡或页面为空白(尽管是.jnlp启动代码)?
代码
下面是用于启动.jnlp文件的代码:
<?php
$map_name = isset($_GET['name']) ? filter_var($_GET['name'], FILTER_SANITIZE_STRING ) : redirect();
$map_version = isset($_GET['version']) ? filter_var($_GET['version'], FILTER_SANITIZE_NUMBER_INT ) : redirect();
$expiration = (time() + (2*24*60*60)) * 1000;
$java = isset($_GET['java']) ? filter_var($_GET['java'], FILTER_SANITIZE_STRING ) : "false";
// check if java is ready, then execute the chip updater
if( $java == "ready" ){
// load jnlp template
$dom = new DOMdocument('1.0', 'utf-8');
$dom->formatOutput = true;
$dom->load('template.jnlp.php');
$node = $dom->getElementsByTagName("application-desc")->item(0); // locate the start place and prep for insertion
// map name attribute
$var = $dom->createElement("argument", base64_encode($map_name)); // place a new argument tag and place an encoded name there
$node->appendChild($var);
// map version attribute
$var = $dom->createElement("argument", base64_encode($map_version)); // place a new argument tag and place an encoded version there
$node->appendChild($var);
// set expiration attribute
$var = $dom->createElement("argument", base64_encode($expiration)); // place a new argument tag and place an encoded expiration time there
$node->appendChild($var);
// output jnlp mime header and force download=
header("Content-Type: application/x-java-jnlp-file");
header("Content-Disposition: attachment; filename=update.jnlp");
//header("Content-Type: text/xml");
// output xml content
echo $dom->saveXML();
//echo $dom->saveXML($node);
} // end
else{
echo <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head></head>
<body>
<script src="http://www.java.com/js/deployJava.js" type="text/javascript"><!-- // --></script>
<script type="text/javascript">
if (deployJava.versionCheck('1.6') || deployJava.versionCheck('1.7')) {
var str = location.href;
var z = str.replace("https://","http://");
var n = z.replace("?download=1","");
var url = n + "&java=ready";
window.location = url; // possibly replace with = ((location.href).replace("?download=1","")) + "&java=ready"
}
else{
alert("We have detected that you either do not have Java installed, or that it may be an older version. We are redirecting you to the Java download site where you will be able to install the newest version of Java. <!!! -- If the window does not load, you may need to allow popups from our site. Please watch for a popup warning and allow it to then relaunch! -- !!!>");
var url="./update2.php";
window.open(url);
window.history.back();
}
</script>
</body>
</html>
EOD;
}注意:我知道有一些不好的做法,比如使用$_GET()而不是$_POST(),由于系统的设置方式,修复这些问题需要时间。我还了解到DOM对象正在从我的网页抓取所有东西,如果我在我的系统框架的同一页上使用这段代码,就会导致错误。这段代码是在我加入公司之前开发的,我正在试着看看是否可以调整它以使其工作,或者是否需要采取不同的方法。
我很感谢你能提供的任何意见。谢谢!
发布于 2013-04-08 23:02:04
我想出来了。在这种情况下,我仍然需要在一个单独的页面中打开它--这确实违背了为什么要构建它的目的。但是,我使用了一个<iframe>,它允许我正确地运行文件。我发现如果我使用display:none隐藏了<iframe>,它仍然可以正确下载.jnlp文件。
因此,如果有人遇到类似的解决方案,有一种方法。如果有人知道,我会有兴趣学习一种不同的方式。
https://stackoverflow.com/questions/15691755
复制相似问题