为什么从 JSP 生成的动态 JNLP 总是因 localhost href 而失败?

发布于 2024-09-26 06:12:56 字数 2420 浏览 0 评论 0原文

我有一个 JSP,它会输出 JNLP 文件,如下所示。部署后在本地主机上工作 到远程服务器时,Java Web Start 出错并出现异常 -

无法加载资源: http://localhost :8080/jnlp/myjnlp.jnlp

ExitException[ 3]com.sun.deploy.net.FailedDownloadException: Unable to load resource: http: // localhost:8080/jnlp/myjnlp.jnlp
 at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
 at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
 at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
 at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
 at com.sun.javaws.Launcher.launch(Unknown Source)
 at com.sun.javaws.Main.launchApp(Unknown Source)
 at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
 at com.sun.javaws.Main$1.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)

包含的 JNLP 文件正在根据服务器的 URL 替换其代码库行。将调试器附加到 JSP 会显示正确的代码库行以及服务器的 IP/主机名。

不明白 localhost 来自哪里?

<%@ page import="java.io.*" %>
<%@ page contentType="application/x-java-jnlp-file" language="java" %>
<%
  response.setHeader("Cache-Control", "no-cache");
  response.setHeader("Pragma", "no-cache");
  response.setDateHeader("Expires", -1);
  response.setContentType("application/x-java-jnlp-file");

// Generating the codebase for the JNLP. This URL will be used for downloading this jsp and the jar
  StringBuffer jspUrlsb = request.getRequestURL();
  String url = jspUrlsb.substring(0,jspUrlsb.lastIndexOf("/"));
  url = url.substring(0,url.lastIndexOf("/"));
  String jnlpCodebase =  url+ "/jnlp/";

  String tool = request.getParameter("tool");
  tool = tool==null || tool.length()==0 ? "myjnlp" : tool;

  String jnlpFile =  tool+".jnlp";
  response.setHeader("Content-Disposition", "filename=\""+jnlpFile+"\";");


  String path = config.getServletContext().getRealPath(request.getContextPath());

  FileInputStream fis = new FileInputStream(new File(path,"/jnlp/"+jnlpFile));
  InputStreamReader isr = new InputStreamReader(fis);
  BufferedReader br = new BufferedReader(isr);

  String line = null;
  while ((line = br.readLine()) != null) {  //consuming the stream
    if (line.startsWith("<jnlp")) {
      line =  "<jnlp  codebase=\""+jnlpCodebase+"\" href=\""+jnlpFile+"\" spec=\"6.0+\">";
    }
%>
    <%=line%>
<%
  }
  br.close();
  isr.close();
  fis.close();
%>

I have a JSP that spits out a JNLP file as shown below. Work son localhost, when deployed
to a remote server, Java Web Start errors out with an exception -

Unable to load resource: http://localhost:8080/jnlp/myjnlp.jnlp

ExitException[ 3]com.sun.deploy.net.FailedDownloadException: Unable to load resource: http: // localhost:8080/jnlp/myjnlp.jnlp
 at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
 at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
 at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
 at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
 at com.sun.javaws.Launcher.launch(Unknown Source)
 at com.sun.javaws.Main.launchApp(Unknown Source)
 at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
 at com.sun.javaws.Main$1.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)

The included JNLP file is getting its codebase line replaced based on server's URL. Attaching a debugger to the JSP show sthe correct codebase line with server's IP /Host name.

Don't understand where the localhost comes from ?

<%@ page import="java.io.*" %>
<%@ page contentType="application/x-java-jnlp-file" language="java" %>
<%
  response.setHeader("Cache-Control", "no-cache");
  response.setHeader("Pragma", "no-cache");
  response.setDateHeader("Expires", -1);
  response.setContentType("application/x-java-jnlp-file");

// Generating the codebase for the JNLP. This URL will be used for downloading this jsp and the jar
  StringBuffer jspUrlsb = request.getRequestURL();
  String url = jspUrlsb.substring(0,jspUrlsb.lastIndexOf("/"));
  url = url.substring(0,url.lastIndexOf("/"));
  String jnlpCodebase =  url+ "/jnlp/";

  String tool = request.getParameter("tool");
  tool = tool==null || tool.length()==0 ? "myjnlp" : tool;

  String jnlpFile =  tool+".jnlp";
  response.setHeader("Content-Disposition", "filename=\""+jnlpFile+"\";");


  String path = config.getServletContext().getRealPath(request.getContextPath());

  FileInputStream fis = new FileInputStream(new File(path,"/jnlp/"+jnlpFile));
  InputStreamReader isr = new InputStreamReader(fis);
  BufferedReader br = new BufferedReader(isr);

  String line = null;
  while ((line = br.readLine()) != null) {  //consuming the stream
    if (line.startsWith("<jnlp")) {
      line =  "<jnlp  codebase=\""+jnlpCodebase+"\" href=\""+jnlpFile+"\" spec=\"6.0+\">";
    }
%>
    <%=line%>
<%
  }
  br.close();
  isr.close();
  fis.close();
%>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

顾忌 2024-10-03 06:12:56

不明白本地主机来自哪里?

我相信它来自本地缓存的 JNLP 文件。有多种方法可以检验这一理论,其中一些方法比其他方法更可靠。

1) 在从未在本地主机测试中使用过的 PC 上尝试 Web 版本。

对于开发机本身。

2) 在启动“实时”网络版本之前,从 Java 缓存 卸载应用程序。或者..

3) 出于每次测试的目的,完全移动缓存。


As two asides..

从上面的代码片段中我不清楚 JNLP href 是否被写入响应。如果是,请将其删除。在动态生成的 JNLP 中包含 href 通常是不必要的,而且会适得其反。

请编辑您的帖子,将输入/输出、代码/代码片段、HTML/XML 格式化为代码。

Don't understand where the localhost comes from ?

I believe it comes from the JNLP file that is cached locally. There are various ways to test this theory, some more reliable than others.

1) Try the web version on a PC never used in testing on the localhost.

For the development machine itself.

2) Uninstall the application from the Java Cache before launching the 'live' web based version. Or..

3) Move the cache entirely, for the purposes of each test.


As two asides..

I was not clear from the code snippets above whether the JNLP href was being written to the response. If it is, remove it. It is usually both unnecessary and counterproductive to include the href in a dynamically generated JNLP.

Please edit your post to format the input/output, code/code snippets, HTML/XML as code.

最佳男配角 2024-10-03 06:12:56

尽管使用 Java 6u21,我还是被迫对代码库进行硬连线。这应该在 18+ 更新中得到修复,但对我来说不起作用。硬连线代码库 URL 后,它就可以工作了。

Despite using Java 6u21 i was forced to hardwire the codebase. This was supposed to have been fixed in update 18+ but didn't work for me. After hardwiring the codebase URL it works.

后eg是否自 2024-10-03 06:12:56

如果您使用动态 jnlp,则必须动态对文件进行签名,即从网络服务器调用 jarsigner 以及动态生成的 jnlp,即首先将它们打包。

If you use a dynamic jnlp you have to dynamically sign the files, i.e. invoke jarsigner from the webserver along w/ the dynamically generated jnlp, i.e. jar 'em first as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文