title: Generate JNLP dynamically
body: <p>I need to pass argument to JNLP dynamically for which I tried using a servlet which extends <code>JnlpDownloadServlet</code> and then includes a jsp which has all the JNLP XML written into it.</p>
  
  <p>But when I invoke the downloaded JNLP I get <code>BadFieldException</code>.</p>
  
  <h2>Servlet</h2>
  
  <pre><code>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);  
  }  
  </code></pre>
  
  <h2>jnlp.jsp</h2>
  
  <p>Used for dumping dynamic JNLP:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jnlp spec="1.0+" codebase=&lt;%=request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ request.getContextPath() + "/" %&gt; href="test.jnlp"&gt;
    &lt;information&gt;
     &lt;title&gt;Demo&lt;/title&gt;
     &lt;vendor&gt;Sun Microsystems, Inc.&lt;/vendor&gt;
    &lt;/information&gt;
    &lt;security&gt;
     &lt;all-permissions/&gt;
    &lt;/security&gt;
    &lt;resources&gt;
     &lt;j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/&gt;
     &lt;jar href="lib/test.jar" main="true" /&gt;
    &lt;/resources&gt;
    &lt;application-desc name="Dynamic Tree Demo Application" main-class="org.Test" width="300"   height="300"&gt;
         &lt;argument&gt;&lt;%=request.getParameter("arg1")%&gt;&lt;/argument&gt;  
         &lt;argument&gt;&lt;%=request.getParameter("arg2")%&gt;&lt;/argument&gt;
    &lt;/application-desc&gt;
    &lt;update check="background"/&gt;
  &lt;/jnlp&gt;
  </code></pre>
  
  <p>I cannot see the request parameters being received correctly in downloaded JNLP but the above <code>request.getScheme</code> and <code>request.getServerName</code> seem to be working fine. Because of argument value not being received correctly I get <code>BadFieldException</code> when JNLP tries to execute.</p>
  
  <p>How to solve this?</p>