通过JNLP传递动态参数

ray*_*man 9 java apache jnlp java-web-start web

我正在使用JavaScript来执行JNLP,最终将执行我的客户端.

我试图通过JavaScript执行将参数传递给JNLP并通过我的客户端内的JNLP获取这些参数.

JavaScript正在执行此URL,例如:

http://localhost:8080/MyJnlp.jnlp?login=14hhh765p&pass=ggyyktff
Run Code Online (Sandbox Code Playgroud)

现在我的JNLP将尝试以<application-desc name tag这种方式获取参数:

<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>
Run Code Online (Sandbox Code Playgroud)

但它没有用.

我无法以这种方式在我的客户端代码中检索这些参数:

login=getParamsFromJnlp("login")
..

public String getParamsFromJnlp(String key) {
    return System.getProperty(key);
}
Run Code Online (Sandbox Code Playgroud)

JNLP在APACHE2.2中

知道什么是错的吗?

Aks*_*ert 10

为了能够将http参数插入到应用程序的参数中,需要根据请求动态地"构造".jnlp文件,因为直到那时您才知道将使用哪些http参数.

java-web-start的工作方式是它会多次下载.jnlp,但除了它第一次从codebase中指定的url和jnlp元素的href属性下载文件之外.

因此,在元素中动态添加argument-element是不够的,还需要将它添加到codebase/href属性中

<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>
Run Code Online (Sandbox Code Playgroud)