【发布时间】:2012-06-14 18:02:05
【问题描述】:
我需要动态地将参数传递给 JNLP,为此我尝试使用扩展 JnlpDownloadServlet 的 servlet,然后包含一个将所有 JNLP XML 写入其中的 jsp。
但是当我调用下载的 JNLP 时,我得到了BadFieldException。
小服务程序
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:
<?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>
我看不到在下载的 JNLP 中正确接收到请求参数,但上面的 request.getScheme 和 request.getServerName 似乎工作正常。由于未正确接收参数值,当 JNLP 尝试执行时,我得到 BadFieldException。
如何解决?
【问题讨论】:
-
实际上更难,因为您需要稍后将 jnlp 包含在 jar 中(对于已签名的 jar),因此 jar 也必须动态签名
-
您确定在调用中使用了参数吗?你能提供你用来下载jnlp的网址吗?
-
我不打算再次将 jnlp 包含在 jar 中,没有它也可以正常工作。
-
我正在尝试在 Struts 上做同样的事情。你能告诉我你的 web.xml 和 struts-config.xml 应该是什么样子吗?
-
在我的例子中,当我扩展 JnlpDownloadServlet 类时,抛出了一个运行时异常,上面写着 SEVERE: Allocate exception for servlet JnlpDownloadServlet java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet。知道为什么会发生这种情况吗?我正在使用 Java Samples and Demos 中的 jnlp-servlet.jar、jnlp.jar 和 jardiff.jar。
标签: java dynamic jnlp java-web-start