简体   繁体   中英

Passing Arguments to JNLP from a JSP

I'm working on replacing an applet with an application launched with Java Web Start. So far in my demo version developed in Netbeans, I'm able to generate the launch.jnlp with the arguments set to the desired values:

<application-desc main-class="myPkg.MyClass">
    <argument>action=someAction</argument>
    <argument>objId=1234abc</argument>
    <argument>userName=user1</argument>       
</application-desc>

But what this JWS-launched application has to do in real life is to set the arguments in the JNLP based on the values selected by and related to the user of the web application that would launch it.

I realize this question has been asked before, but in most cases several years have passed since those questions were answered and I am unsure if the answers are still applicable, given the security lockdown that Java has been put through by the browser vendors. Is the way to accomplish this these days to send the argument values via HTTP request parameters, ie,

[codebase]/launch.jnlp?action=someAction&objId=1234abc&userName=user1 ?

You can pass parameters to an applet started via JWS just as you can when starting an applet in the browser, eg in the JNLP. However, you must build the JNLP containing these server-side AFAIK; passing them as URL-Args directly to javaws is not possible (the URL only makes the browser download the jnlp and throw it at javaws's feet, and that again would fetch it from the server possibly again , so be sure to build the

<jnlp codebase="http://@JAVA_WEB_START_IP@" href=" /launch.jnlp?action=someAction&objId=1234abc&userName=user1 "

so that it matches the parameters with which you invoke the jnlp "cgi"

So you need a cgi named launch.jnlp putting the parameters into a jnlp template

1) at the href as url parameters

2) in the applet-desc

 <applet-desc main-class="com.xyz.class" 
  width="850" height="650" name="Applet Name">
   <param name="action" value="someAction"/>
   <param name="objId" value="1234abc"/>
   <param name="userName" value="user1"/>
 </applet-desc>

At least this is the possibility I'm aware of and that works for me.

Edit

Same applies if you are using an application-desc instead, then instead of the <param s you have to fill the <argument s accordingly, besides the href...

虽然我的实现仍在进行中,但我确实想说,到目前为止对我有用的是在Servlet中动态创建JNLP,并将其写到与HTTPResponse对象关联的流中...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM