java 动态生成 JNLP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11038773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generate JNLP dynamically
提问by Harshdeep
I need to pass argument to JNLP dynamically for which I tried using a servlet which extends JnlpDownloadServlet
and then includes a jsp which has all the JNLP XML written into it.
我需要动态地将参数传递给 JNLP,为此我尝试使用一个 servlet,该 servlet 扩展JnlpDownloadServlet
并包含一个 jsp,其中写入了所有 JNLP XML。
But when I invoke the downloaded JNLP I get BadFieldException
.
但是当我调用下载的 JNLP 时,我得到BadFieldException
.
Servlet
小服务程序
public class TestServlet extends JnlpDownloadServlet {
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
HttpServletRequest request = (HttpServletRequest) req;
res.setContentType("application/x-java-jnlp-file");
request.getRequestDispatcher("/jnlp.jsp").include(request, res);
}
jnlp.jsp
jnlp.jsp
Used for dumping dynamic JNLP:
用于转储动态 JNLP:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase=<%=request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ request.getContextPath() + "/" %> href="test.jnlp">
<information>
<title>Demo</title>
<vendor>Sun Microsystems, Inc.</vendor>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="lib/test.jar" main="true" />
</resources>
<application-desc name="Dynamic Tree Demo Application" main-class="org.Test" width="300" height="300">
<argument><%=request.getParameter("arg1")%></argument>
<argument><%=request.getParameter("arg2")%></argument>
</application-desc>
<update check="background"/>
</jnlp>
I cannot see the request parameters being received correctly in downloaded JNLP but the above request.getScheme
and request.getServerName
seem to be working fine. Because of argument value not being received correctly I get BadFieldException
when JNLP tries to execute.
我看不到正在接收的请求参数正确下载的JNLP但上面request.getScheme
并request.getServerName
似乎是工作的罚款。由于没有正确接收参数值,我BadFieldException
在 JNLP 尝试执行时得到了。
How to solve this?
如何解决这个问题?
采纳答案by Andrew Thompson
Logically, href="test.jnlp"
should be something like href="test.jnlp?arg1=blah&arg2=tah"
.
从逻辑上讲,href="test.jnlp"
应该类似于href="test.jnlp?arg1=blah&arg2=tah"
.
AFAIU the JWS client will reach back to the server using the exact coodebase
/href
stated in the JNLP.
AFAIU JWS 客户端将使用JNLP 中的确切coodebase
/href
说明返回到服务器。
Also, definitely listen to what bestsss has to say.
另外,一定要听听 bestsss 怎么说。
回答by Lawrence
Maybe to old for being useful but I actually patched the Sun servlet code. There is a Class JnlpFileHandler where the actual substitutions are done.... Just saying... ;-) If anyone is interested I can give you the code including a little explanation. I did not waste too much tima at it but all I can say is that I truly hope the rest of SUN's code is written in a LOT more respect to OO principles...
也许因为有用而老了,但我实际上修补了 Sun servlet 代码。有一个 JnlpFileHandler 类在其中完成了实际的替换......只是说...... ;-) 如果有人感兴趣,我可以给你代码,包括一些解释。我并没有浪费太多时间,但我只能说我真的希望 SUN 的其余代码在编写时更加尊重 OO 原则......