9

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

我正在尝试通过 JavaScript 执行将参数传递给 JNLP,并在我的客户端中通过 JNLP 获取这些参数。

例如,JavaScript 正在执行此 URL:

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

现在我的 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>

但它没有用。

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

login=getParamsFromJnlp("login")
..

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

JNLP 在 APACHE2.2 内部

知道有什么问题吗?

4

2 回答 2

10

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

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

所以在元素中动态添加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>
于 2012-12-05T12:34:33.683 回答
1

你确定JSP的响应类型是“application/x-java-jnlp-file”吗?

如果不是,请在 JSP 顶部提及并检查。

<% response.setContentType("application/x-java-jnlp-file"); %>
于 2012-12-05T11:07:01.600 回答