动态生成 JNLP [英] Generate JNLP dynamically

查看:41
本文介绍了动态生成 JNLP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要动态地将参数传递给 JNLP,为此我尝试使用扩展 JnlpDownloadServlet 的 servlet,然后包含一个写入了所有 JNLP XML 的 jsp.

I need to pass argument to JNLP dynamically for which I tried using a servlet which extends JnlpDownloadServlet and then includes a jsp which has all the JNLP XML written into it.

但是当我调用下载的 JNLP 时,我得到 BadFieldException.

But when I invoke the downloaded JNLP I get BadFieldException.

public class TestServlet extends JnlpDownloadServlet {  
public void service(ServletRequest req, ServletResponse res)  throws ServletException, IOException {  
HttpServletRequest request = (HttpServletRequest) req;
res.setContentType("application/x-java-jnlp-file");
request.getRequestDispatcher("/jnlp.jsp").include(request, res);  
}  

jnlp.jsp

用于转储动态 JNLP:

jnlp.jsp

Used for dumping dynamic JNLP:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase=<%=request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ request.getContextPath() + "/" %> href="test.jnlp">
  <information>
   <title>Demo</title>
   <vendor>Sun Microsystems, Inc.</vendor>
  </information>
  <security>
   <all-permissions/>
  </security>
  <resources>
   <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
   <jar href="lib/test.jar" main="true" />
  </resources>
  <application-desc name="Dynamic Tree Demo Application" main-class="org.Test" width="300"   height="300">
       <argument><%=request.getParameter("arg1")%></argument>  
       <argument><%=request.getParameter("arg2")%></argument>
  </application-desc>
  <update check="background"/>
</jnlp>

我无法在下载的 JNLP 中看到正确接收的请求参数,但上面的 request.getSchemerequest.getServerName 似乎工作正常.由于未正确接收参数值,我在 JNLP 尝试执行时收到 BadFieldException.

I cannot see the request parameters being received correctly in downloaded JNLP but the above request.getScheme and request.getServerName seem to be working fine. Because of argument value not being received correctly I get BadFieldException when JNLP tries to execute.

如何解决这个问题?

推荐答案

从逻辑上讲,href="test.jnlp" 应该类似于 href="test.jnlp?arg1=blah&arg2=tah".

Logically, href="test.jnlp" should be something like href="test.jnlp?arg1=blah&arg2=tah".

AFAIU JWS 客户端将使用 JNLP 中规定的确切 codebase/href 返回到服务器.

AFAIU the JWS client will reach back to the server using the exact coodebase/href stated in the JNLP.

另外,一定要听听 bestsss 怎么说.

Also, definitely listen to what bestsss has to say.

这篇关于动态生成 JNLP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆