有没有一种方法可以仅使用html即时触发或执行下载的文件? 这是我正在使用的简单脚本,此调用将仅下载我的应用程序,但我的目标不仅是简单下载它,我需要的是直接在此链接上下载的内容上执行
href="http://localhost:8088/main/system/launch/client/MyApp.jnlp"
赞赏TIA的任何建议或评论。
答案 0 :(得分:0)
您可能想阅读以下内容:https://docs.oracle.com/javase/tutorial/deployment/webstart/deploying.html。您尝试运行的文件有点像Java applet,并且需要在客户端上安装Java并获得许可等才能打开。
该页面详细介绍了所需的html标记,尤其是这一部分
Create the HTML page from which your application will be launched. Invoke Deployment Toolkit functions to deploy the Java Web Start application.
In the example, the Dynamic Tree Demo application is deployed in JavaWebStartAppPage.html.
<body>
<!-- ... -->
<script src=
"https://www.java.com/js/deployJava.js"></script>
<script>
// using JavaScript to get location of JNLP
// file relative to HTML page
var dir = location.href.substring(0,
location.href.lastIndexOf('/')+1);
var url = dir + "dynamictree_webstart.jnlp";
deployJava.createWebStartLaunchButton(url, '1.7.0');
</script>
<!-- ... -->
</body>
我的猜测是,您可以通过执行以下操作来简化它:
<body>
<!-- ... -->
<script src="https://www.java.com/js/deployJava.js"></script>
<script>
deployJava.createWebStartLaunchButton(
"http://localhost:8088/main/system/launch/client/MyApp.jnlp",
"1.7.0"
);
</script>
<!-- ... -->
</body>
当您运行上述代码时,似乎在其下方显示了以下内容:
<a href='javascript:if (!deployJava.isWebStartInstalled("1.7.0")) {if (deployJava.installLatestJRE()) {if (deployJava.launch("https://docs.oracle.com/javase/tutorialJWS/samples/deployment/dynamictree_webstartJWSProject/dynamictree_webstart.jnlp")) {}}} else {if (deployJava.launch("https://docs.oracle.com/javase/tutorialJWS/samples/deployment/dynamictree_webstartJWSProject/dynamictree_webstart.jnlp")) {}}' onmouseover="window.status=''; return true;"><img src="//java.com/js/webstart.png" border="0"></a>
因此,您可以尝试仅在href
内运行JavaScript的修改版本。就您而言,可能是:
const url = "http://localhost:8088/main/system/launch/client/MyApp.jnlp";
if (!deployJava.isWebStartInstalled("1.7.0")) {
if (deployJava.installLatestJRE()) {
deployJava.launch(url);
}
} else {
deployJava.launch(url);
}