我有一个 JSP,它会吐出一个 JNLP 文件,如下所示。工作子 localhost,当部署到远程服务器时,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 /主机名。
不明白本地主机来自哪里?
<%@ 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();
%>