url parameters in jnlp href attribute
Asked Answered
M

3

4

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 when launching the files.

(JNLP download-servlet and jsp-page parses the url-parameters and inputs them in the argument further down)

The interesting parts of the 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 might or might not be a bug,

Q1: have I been using the href-attribute in a correct way?

Q2: Any smart ideas how to get around the problem?

Mcdougall answered 2/9, 2012 at 12:15 Comment(3)
just tested, the jws launcher crashes as soon as i put a ? in a attributevalue. so i think the answer to q1 is yesMcdougall
I am not entirely certain, but there are a number of JWS apps. that do pretty much what you describe - passing parameters in the URL. Try using the JNLPDownloadServlet.Pursue
Im not sure what the servlet could do. Jawa-web-start launcher crashes as soon as there is a ?-mark in any attributevalueMcdougall
L
7

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

Larhondalari answered 3/9, 2012 at 11:56 Comment(2)
We spent a whole lot time looking at this issue until we looked at thread. When we saved the jnlp file as UTF-8 encoded it started working. But by default the JNLP gets downloaded as ansi encoded and never worked after this update.Bondman
After investigating further, the difference seems to be that the UTF-8 "encoded" files differ from the ANSI file only in the presence of the BOM. If we remove the BOM, JNLP files with questionmarks in them fail when invoked from the command line. Sheesh!Dratted
C
3

This problem has been added in Oracle Bug Database at:

Collier answered 9/9, 2012 at 9:27 Comment(1)
This bug is not available. (probably locked from public view)License
S
1

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.

Shulamith answered 21/3, 2014 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.