【问题标题】:How to pass arguments to JNLP launched Swing application?如何将参数传递给 JNLP 启动的 Swing 应用程序?
【发布时间】:2016-09-19 16:29:48
【问题描述】:

我需要在调用 servlet 时在客户端打开一个 Java Swing 应用程序。在通过 JNLP 在客户端浏览器上打开的 Swing 应用程序的 main 方法中也需要接收很少的参数。在我的情况下,swing 应用程序正在打开,但无论如何都没有收到任何参数。

我的 JNLP 文件不是动态构建的。它是一个静态文件。这里是:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" 
      codebase="http://localhost:8085/TestWebApp" 
      href="ContactEditor.jnlp">

    <information>
        <title>JNLP Example</title>
        <vendor>Catalyst Software</vendor>
        <homepage href="http://localhost:8085/TestWebApp" />
        <description>JNLP Testing</description>
    </information>

    <security>
        <all-permissions/>
    </security>

    <resources>
        <j2se version="1.6+" />
        <jar href="ContactEditor.jar" />
    </resources>

    <application-desc main-class="my.contacteditor.ContactEditorUI">
        <argument>00001</argument>
        <argument>Harish Prasad</argument>
        <argument>220153429088</argument>
    </application-desc>    

    <security>
        <all-permissions/>
    </security>

</jnlp>

请建议如何将参数从 servlet 动态传递到 swing 应用程序。

我的问题是:

  1. 我必须在我的 Swing 程序中编写什么代码?
  2. 我必须在 JNLP 文件中提及什么?
  3. 我应该如何从 servlet 传递值?

【问题讨论】:

  • 请务必使用 JaNeLA 检查 JNLP,可在我的 share drive 获得。请注意,上面的 JNLP 有两个 &lt;security&gt; 元素..

标签: java swing servlets java-web-start jnlp


【解决方案1】:
  1. JNLP File Syntax 指定“每个参数包含(按顺序)要传递给 main 的附加参数。”

    public static void main(String[] args) { 
        for (String value : args) {
            …
        }
    }
    
  2. 您的&lt;argument&gt;syntax 似乎正确,正如here 所指定的那样; &lt;security&gt; 元素出现两次,如 here 所述;验证@AndrewThompson 提到的here 的语法。

  3. 您需要动态构建 JNLP 文件,如 here 所述。

【讨论】:

  • “语法显示正确” &lt;security&gt; 元素出现两次。
  • @AndrewThompson:感谢您的评论;我太专注于&lt;argument&gt; 语法。也感谢您链接到JaNeLA。是否有引用它的规范问答?如果您认为合适,我很乐意编辑损坏的链接。
  • “是否有引用它的规范问答?” 我的大部分规范问答都已(大力支持但)关闭。害怕会招致“垃圾邮件”的指责。 :(
  • @AndrewThompson: Hypnotoad 建议,“以前在我的 pscode.org 域中可用的一些工具可以从我的Google Share Drive 下载。”
猜你喜欢
  • 1970-01-01
  • 2023-03-04
  • 2012-12-24
  • 1970-01-01
  • 2020-04-29
  • 1970-01-01
  • 2021-01-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多