url parameters in jnlp href attribute

后端 未结 3 1171
终归单人心
终归单人心 2020-12-18 09:12

I\'ve been using url parameters to pass arguments to the main-method of the .jar application. After updating to latest jre 7u7 on windows 7, Java-web-start launcher crashes

相关标签:
3条回答
  • 2020-12-18 09:35

    I get the same problem today. I didn't find anything on the net, but I tried to replace the '?' with the HTML entity '?' and it works.

    0 讨论(0)
  • 2020-12-18 09:52

    I have looking for this answer for quite sometime and never got a concrete solution. So here I am after ultimately solving it. I shall put forth the solution below.

    Current situation: Had a simple java application to launch from a browser with parameters. The existing route was browser-->index.html-->calls my jnlp file-->calls the main method of my java class.

    Needed situation: Now the user would send the arguments say, username from the browser to be sent all the way to the main method of the java class.

    Solution:

    • Don't waste time trying to change the jnlp file only.
    • Change the index.html as follows:

      1. Add function getUrlParameters() (google it) to the javascript part of the index.html

      2. Get the value of the username with the call usernameParam = getUrlParameters("username", "", true)

      3. Form the like this URL = 'nameOfYourJSPFile.jsp?username='+usernameParam
    • Create a new jsp file (this is a must) like:

      <%@ page contentType="application/x-java-jnlp-file" %>   
      <%@ page session="true" %>   
      <%   
      response.setDateHeader ("Expires", 0); //prevents caching at the proxy server 
      // Getting the URL parameters from the request
      final String USERNAME_PARAM = "username";
      String paramUsername = request.getParameter(USERNAME_PARAM);
      %> 
      <?xml version="1.0" encoding="iso-8859-1"?>
      <jnlp spec="1.0+" codebase="http://localhost:8080/" href="<nameOfYourJSPFile>.jsp?    <%=USERNAME_PARAM + "=" + paramUsername%>">
      <information>
      </information>
      <security>
          <all-permissions/>
      </security>
      
      <resources>
                 Your resources...
      </resources>
      
      <application-desc main-class="Complete.package.yourClassNameContainingMain">
           <argument><%=paramUsername%></argument>
      </application-desc>
      </jnlp>
      
    • Once this URL is formed you will be sending this to: IFrameDoc.location.replace(URL); in the same index.html

    You will get the passed username value in the String[] args of the main method. So now you can check if the param value exists, if so, form the URL with the jsp file or continue with the old jnlp file directly.

    0 讨论(0)
  • 2020-12-18 09:56

    This problem has been added in Oracle Bug Database at:

    0 讨论(0)
提交回复
热议问题