我需要动态地将参数传递给 JNLP,为此我尝试使用扩展的 servlet,JnlpDownloadServlet
然后包含一个将所有 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
工作正常。由于没有正确接收到参数值,我BadFieldException
在 JNLP 尝试执行时得到。
如何解决这个问题?