Passing dynamically parameters to a Java Web Start App (JNLP)
![]() |
| Copyright br3akthru @freedigitalphotos.net |
Today the web is everywhere - even the smallest handhelds are unuseable without linking to the world wide internet. Thus it is no suprise that the Java is trying to crossover the computer and the internet to get so cute together using Java Web Start Technology. This technique is running directly on a client machine is a successor of the 90s propagated applet-technology. Nevertheless i expect in my curren portal-project some issues with that kind of piece. Customers requirement describes the approach to start a client-application with parameters via browser. This is only easily possible with java using applets or Java Web Start with all-permissions to handle files on clients-machine.
To pass dynamically the parameters to a client-application (which can be read out on the Main-function of the main class) we have to do some effords to reach the goal as out of the box Java Web Start does not provide this nice kind of feature. So why we bothering about if we even can fix it?
Following steps we have to work out:
1) Create a servlet that does 2 things: set the contenttype to application/x-java-jnlp-file and include via requestdispatcher a jsp file that renders our dynamic parameters to a jnlp file. So there does not exist any static jnlp file so we can do al lthat things we want to pass along the jnlp-file.
2) Create the jsp file that renders jnlp output.
2) Update web.xml file
3) Update the hyperlink to the program to pass the parameters.
Lets start with the first step:
import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;
import com.sun.javaws.servlet.JnlpDownloadServlet;
public class TstServlet extends JnlpDownloadServlet {
public void service(ServletRequest req, ServletResponse res)
throws ServletException, IOException {
HttpServletRequest _req = (HttpServletRequest) req;
res.setContentType("application/x-java-jnlp-file");
_req.getRequestDispatcher("/jnlp.jsp").include(req, res);
}
}
Second step is to create the jsp file that renders valid jnlp-xml content
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0" codebase="http://localhost:8080/">
<information>
<title>WebPad 1.0</title>
<vendor>Sun Microsystems, Inc.</vendor>
</information>
<resources>
<property name="jnlp.publish-url" value="http://localhost:8080/publish"/>
<j2se version="1.3+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="webpad.jar" version="1.0"/>
</resources>
<application-desc main-class="WebPad">
<argument><% request.getParameter("type") %> </argument>
<argument><% request.getParameter("arg") %> </argument>
</application-desc>
<security>
<all-permissions/>
</security>
Next one is to edit the web.xml file
<servlet> <servlet-name> TstServlet </servlet-name> <servlet-class> TstServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>TstServlet</servlet-name> <url-pattern>/jnlp/*</url-pattern> </servlet-mapping>
Last one is to pass the appropriated paramters to your link you wish to pass to:
<a href="jnlp/webpad?program=soffice&arg=headless
Comments
5 Responses to “Passing dynamically parameters to a Java Web Start App (JNLP)”
Leave a Reply


Sebastian Wenzky works since october 09 as a ecm-consultant at Westernacher in Stuttgart. Alfresco, Spring, Hibernate, JBPM and - to much - coffee are now his companions. The corresponding company the right way to go.
Seems something is missing, I cannot get this to replace the parameters. The Webstart is starting and the arguments are not filled in. Also the $$codebase that the standard JnlpDownloadServlet does for you is not being replaced.
You did not name your different files, so I was guessing. Where is the webpad file mentioned in the anchor tag? Also you have \\"program\\" as a parameter, but your argument in the jnlp-xml is \\"type\\",
OK, I did get this figured out. For the webpad, I just created a blank jsp page and placed it into the /jnlp directory. The $$codebase is not being replaced though. Here is what I did for that:
<jnlp codebase=\"<%=request.getScheme() + \"://\"
+ request.getServerName() + \":\" + request.getServerPort()
+ request.getContextPath() + \"/\" %>\">
The above codbase strings are being manipulated by this web software, so you will have to remove all the backslashes.
HI there
jnlp web application configuration and flow work.i tried with the above example. but it does not rendering the jar tag. would you please help me out it’s very urgent.
HI There
Yesterday I was given mail about small issue. but now it is working fine. thank you for your article. please post some more articles like this. have a good day