通过 JNLP 传递动态参数 [英] Pass dynamic params via JNLP

查看:22
本文介绍了通过 JNLP 传递动态参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

JavaScript 正在执行此 URL,例如:

The JavaScript is executing this URL for instance:

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

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

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>

但是没有用.

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

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

login=getParamsFromJnlp("login")
..

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

JNLP 在 APACHE2.2 中

The JNLP is inside APACHE2.2

知道出了什么问题吗?

推荐答案

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

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.

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

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.

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

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>

这篇关于通过 JNLP 传递动态参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆