Url parameters in jnlp href attribute

I used url parameters to pass arguments to the main .jar application method. After upgrading to the latest version 7u7 in Windows 7, when starting files, Java-web-start fails.

(The JNLP boot servlet and jsp page parse the URL parameters and add them to the argument further)

Interesting parts of jsp

<jnlp spec="6.0+" codebase="http://localhost:8080/" href="myfile.jnlp?username=charles"> ... <application-desc main-class="MyMain"> <argument><%=request.getParameter("username")%></argument> </application-desc> </jnlp> 

So this may or may not be a mistake,

Q1: Did I use the href attribute correctly?

Q2: Any clever ideas on how to get around the problem?

+4
source share
3 answers

Today I have the same problem. I did not find anything on the net, but I tried replacing '?' with HTML '& # 063;' and it works.

+7
source

This issue has been added to the Oracle Bug at database:

+3
source

I have been looking for this answer for a long time and have never received a specific solution. So, after that I will finally solve this. I will put the solution below.

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

Necessary situation: now the user will send arguments, say, the username from the browser, which will be sent before the main method of the java class.

Decision:

  • Do not waste time trying to modify only the jnlp file.
  • Change index.html as follows:

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

    • Get the value of the username with the name usernameParam = getUrlParameters ("username", "," true ")

    • Configure this URL = 'nameOfYourJSPFile.jsp? Username = '+ usernameParam
  • Create a new jsp file (this is required), for example:

     <%@ 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 has been generated, you will send it: IFrameDoc.location.replace (URL); in the same index.html

In the String [] argument of the main method, you get the value of the passed username. So, now you can check if the parameter value exists, if so, generate the URL with the jsp file or directly go to the old jnlp file.

+1
source

All Articles