我需要在调用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应用程序。
我的问题是:
我必须在Swing程序中编写什么代码?
我必须在JNLP文件中提到什么?
我应该如何传递servlet中的值?
最佳答案
JNLP File Syntax指定“每个参数包含(按顺序)要传递给main
的附加参数”。
public static void main(String[] args) {
for (String value : args) {
…
}
}
您的
<argument>
语法显示正确,如here所指定; <security>
元素出现两次,如here所示;验证@AndrewThompson指出的here语法。您将需要动态构建JNLP文件,如here所述。