gpt4 book ai didi

java - 使用 JSP 的动态 JNLP

转载 作者:行者123 更新时间:2023-12-02 10:35:59 25 4
gpt4 key购买 nike

我有一个 JSP 文件,当通过超链接调用时,该文件返回 JNLP 文件。但它下载为 jsp(xxx.jsp 而不是 xxx.jnlp)文件,尽管内容是预期的 jnlp。

以下是我的 JSP

    <%    
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", "0");
response.setContentType("application/x-java-jnlp-file");
response.setHeader("Cache-Control", null);
response.setHeader("Set-Cookie", null);
response.setHeader("Vary", null);

// An installer must reply with the version number for a given install
if (response.containsHeader("x-java-jnlp-version-id"))
response.setHeader("x-java-jnlp-version-id", "WASClient6.1.0");
else
response.addHeader("x-java-jnlp-version-id", "WASClient6.1.0");
String codeBase = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ request.getContextPath() + "/";
%>

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="<%=codeBase %>">
<information>
<title>XXX</title>
</information>
<security>
<all-permissions/>
</security>
<resources>

</resources>
<application-desc main-class="TestApp">
</application-desc>
</jnlp>

下面是生成的jsp

 <?xml version="1.0" encoding="utf-8"?> 
<jnlp spec="1.0+" codebase="<%=codeBase %>">
<information>
<title>XXX</title>
</information>
<security>
<all-permissions/>
</security>
<resources>

</resources>
<application-desc main-class="TestApp">
</application-desc>
</jnlp>

知道我做错了什么吗?谢谢。

最佳答案

您确实不应该使用 scriptlet,但如果需要,您应该从 scriptlet 生成 jnlp 文件,然后对创建的 jnlp 文件执行 response.redirect

 ServletContext servletContext = session.getServletContext();
String localDir = servletContext.getRealPath("").replace('\\', '/');
File jnlp = new File(localDir + "something.jnlp");
FileWriter fw = new FileWriter(jnlp);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(//contents of jnlp file);
response.sendRedirect(jnlp.getName());

关于java - 使用 JSP 的动态 JNLP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53290462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com