简体   繁体   中英

Building a jnlp from a jsp file

I'm trying to pass dynamic arguments through the jnlp files using a jsp file to start my java application. However i'm really new to JWS so any help would be appreciated.

My question is, what should be in the test.jnlp for it to receive the parameters of username and pass the arguments into the java applciation? I've read many others posts but i still can't get my application to receive the arguments.

Current Code:

JNLP.JSP

   <% 
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", "0");
response.setHeader("Content-Disposition", "filename=\"bb.jnlp\";");
response.setContentType("application/x-java-jnlp-file");
%>
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" 
      codebase=<%=request.getScheme() + "://"+ request.getServerName() + ":" 
+ 
request.getServerPort()+ request.getContextPath() + "/" %> 
      href="test.jnlp&#063;username=<%=request.getParameter("username")%>">
    <information>
        <title>ProBuilder</title>
        <vendor>pAtoms</vendor>
        <homepage href="http://localhost:8080/" />
        <description>ProBuilder</description>
    </information>
    <security>
    <sandbox/>
    </security>
    <resources>
        <j2se version="1.6+" />
        <jar href="ProBuilder.jar" />
    </resources>
    <application-desc main-class="adam.Adam" >
       <argument><%=request.getParameter("username")%></argument>
    </application-desc>
</jnlp>

In your servlet class obtain parameters:

String username = req.getParameter("username");
String pass = req.getParameter("pass");

Assuming req is HttpServletRequest , if you want secure application then better somehow secure your password.

Set attributes in your request:

req.setAttribute(username, "username");
req.setAttribute(pass, "pass");

and dispatch your attributes to jnlp

req.getRequestDispatcher("jnlp.jsp").forward(req, YOUR_HttpServletResponse);

In your jsp obtain attributes like that:

${requestScope.username}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM