动态生成JNLP

Har*_*eep 11 java jnlp dynamic java-web-start

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

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

Servlet的

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);  
}  
Run Code Online (Sandbox Code Playgroud)

jnlp.jsp

用于转储动态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>
Run Code Online (Sandbox Code Playgroud)

我看不到正在接收的请求参数正确下载的JNLP但上面request.getSchemerequest.getServerName似乎是工作的罚款.由于没有正确接收参数值,我BadFieldException在JNLP尝试执行时得到.

怎么解决这个?

And*_*son 8

从逻辑上讲,href="test.jnlp"应该是这样的href="test.jnlp?arg1=blah&arg2=tah".

AFAIU JWS客户端将使用JNLP中的确切coodebase/ href声明返回服务器.

另外,一定要听听最好的话.

  • 我不同意,不是应该添加参数的href,而是用于首先下载jnlp的url.示例:www.example.com/app/servlet/TestServlet?arg1=blah&arg2=tah (2认同)