Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

java - Pass dynamic params via JNLP

I am using JavaScript in order to execute JNLP which in the end will execute my client.

I am trying to pass parameters via JavaScript execution to the JNLP and having those parameters via JNLP inside my client.

The JavaScript is executing this URL for instance:

http://localhost:8080/MyJnlp.jnlp?login=14hhh765p&pass=ggyyktff

Now my JNLP will try to get the parameters in the <application-desc name tag this way:

<application-desc name="..." main-class="com.main.execute" >
        <argument>-nosplash</argument>
        <argument>-q</argument>
    <argument><%=request.getParameter("login")%></argument>
    <argument><%=request.getParameter("pass")%></argument>
</application-desc>

But it didn't work.

I couldn't retrieve those parameters in my client code this way:

login=getParamsFromJnlp("login")
..

public String getParamsFromJnlp(String key) {
    return System.getProperty(key);
}

The JNLP is inside APACHE2.2

Any idea what's wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To be able to insert the http-parameters into the argument of your application, the .jnlp file need to be 'constructed' dynamicly on request, because it is not until then you know which http-parameters that will be used.

The way java-web-start works is that it will download the .jnlp several times, but the apart from the first time it will download the file from the url specified in the codebase and href attributes of the jnlp element.

So it is not enough to add the argument-element dynamicly in the element, you also need to add it to the codebase/href attributes

<jnlp spec="1.0+" 
      codebase=<%=request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ request.getContextPath() + "/" %> 
      href="jnlpfile.jnlp&#063;username=<%=request.getParameter("username")%>&clienttoken=<%=request.getParameter("clienttoken")%>">

    ...
    <application-desc main-class="test.MainClass">
       <argument><%=request.getParameter("username")%></argument>
    </application-desc>
</jnlp>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...