Dynamically create response in JSF

只谈情不闲聊 提交于 2019-12-19 11:49:07

问题


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.

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.

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?


回答1:


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

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

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.

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> 


来源:https://stackoverflow.com/questions/12861447/dynamically-create-response-in-jsf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!