我正在使用 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 中
知道哪里出了问题吗?
最佳答案
为了能够将 http 参数插入到您的应用程序的参数中,.jnlp 文件需要根据请求动态“构建”,因为直到那时您才知道将使用哪些 http 参数。
java-web-start 的工作方式是它会多次下载 .jnlp,但除了第一次它会从 jnlp 元素的代码库和 href 属性中指定的 url 下载文件。
所以仅仅在元素中动态添加argument-element是不够的,还需要在codebase/href属性中添加
<jnlp spec="1.0+"
codebase=<%=request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ request.getContextPath() + "/" %>
href="jnlpfile.jnlp?username=<%=request.getParameter("username")%>&clienttoken=<%=request.getParameter("clienttoken")%>">
...
<application-desc main-class="test.MainClass">
<argument><%=request.getParameter("username")%></argument>
</application-desc>
</jnlp>
关于java - 通过 JNLP 传递动态参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13721587/