在 JSF 中动态创建响应 [英] Dynamically create response in JSF

查看:36
本文介绍了在 JSF 中动态创建响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 JSF 页面上有一个链接.单击此链接时,Java Web Start 应用程序将启动.该应用程序根本不会影响当前页面.应用程序自行启动.

I want to have a link on my JSF page. When you click this link, a Java Web Start application starts. The application doesnt affect the current page at all. The application just starts on its own.

问题是,我需要动态生成启动 Java Web Start 应用程序的 JNLP 文件.基本上我会根据应用程序的状态决定 JNLP 文件的应用程序和参数.

The problem is, I the JNLP file that starts the Java Web Start application needs to be generated on the fly. Basically I will decide which application and what paramaters for the JNLP file depending on the state of the application.

有谁知道我可以做到这一点的方法.是否可以通过单击链接而不影响当前页面来简单地执行动态创建的 JNLP 文件?

Does anyone know of a way that I can accomplish this. Is it possible to execute a dynamically created JNLP file simple by clicking a link and not affecting the current page?

推荐答案

您可以拥有一个 servlet 来捕获对(某些)文件类型 (jnlp) 的请求.

you can have a servlet that captures the requests for (certain) filetypes (jnlp).

我一直在扩展 JnlpDownloadServlet 并结合一个 jsp 文件,该文件用作对单击的链接的响应.

I've been extending JnlpDownloadServlet in combination with a jsp file that is served as response to the clicked link.

http://docs.oracle.com/javase/1.5.0/docs/guide/javaws/developersguide/downloadservletguide.html

必须通过使用 http get 参数和 codebase 属性来保留状态,因为在应用程序启动期间可能会多次下载 jnlp 文件.所以保持状态的唯一方法就是这样做afaik.

The state has to be preserved by using http get parameters together with the codebase attribute as jnlp file might be downloaded more than once during launch of application. So only way to preserve state is to do it this way afaik.

本例中的状态是用户名和客户端令牌.这是我一直在使用的 jsp 文件的一部分:

The state in this example is username and clienttoken. this is parts of the jsp file i've been using:

<?xml version="1.0" encoding="UTF-8"?>
<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")%>">
  <information>
            <title>title</title>
            <vendor>vendor</vendor>
            <description kind="short">short desc</description>
            <icon href="resources/images/icon.jpg" kind="default"/>
  </information>
  <security>
      <all-permissions/>
  </security>
  <resources>
            <java version="1.7+" java-vm-args="-ea" initial-heap-size="128m" max-heap-size="512m" />
            <jar download="eager" href="test.jar"/>
  </resources>
  <application-desc main-class="test.MainClass">
       <argument><%=request.getServerName()%></argument>  
       <argument><%=request.getParameter("username")%></argument>
       <argument><%=request.getParameter("clienttoken")%></argument>
  </application-desc>
  <update check="background"/>
</jnlp> 

这篇关于在 JSF 中动态创建响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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