Harshdeep Harshdeep - 1 year ago 169
Java Question

Generate JNLP dynamically

I need to pass argument to JNLP dynamically for which I tried using a servlet which extends

and then includes a jsp which has all the JNLP XML written into it.

But when I invoke the downloaded JNLP I get


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


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">
<vendor>Sun Microsystems, Inc.</vendor>
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="lib/test.jar" main="true" />
<application-desc name="Dynamic Tree Demo Application" main-class="org.Test" width="300" height="300">
<update check="background"/>

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

How to solve this?

Answer Source

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

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

Also, definitely listen to what bestsss has to say.