Failure to Launch .jnlp
<p>First time I've had to ask a question on here, as I've always been able to find the answer. I have no knowledge of how Java or .jnlp files work. </p>

<p><strong>Project Context</strong></p>

<p>There is a web page on my site that loads a blank page when people click to download a file. This blank page then loads the .jnlp file, which executes the java code when a user initiates it. Unfortunately, many users have a difficult time understanding what is going on. My task is to wrap this download in our Magento system, and add instructions so people know where they are at.</p>

<p><strong>The Problem</strong></p>

<p>Everything is working as envisioned. The only exception is that the .jnlp file displays an error "Unable to launch the application" when launched. The issue is that the entire website's content is being written into the file, which is causing it to fail. The only workaround I have found is to launch the .jnlp file in a new blank window....which defeats the purpose of what I've set out to do.</p>

<p><strong>The Question</strong></p>

<p>Is there a way to launch a .jnlp file on a page without having to open a new tab or the page to be blank (albeit the .jnlp launch code)?</p>

<p><strong>The Code</strong></p>

<p>Here is the code used to launch the .jnlp file:</p>

<pre><code>&lt;?php
$map_name = isset($_GET['name']) ? filter_var($_GET['name'], FILTER_SANITIZE_STRING ) : redirect();
$map_version = isset($_GET['version']) ? filter_var($_GET['version'], FILTER_SANITIZE_NUMBER_INT ) : redirect();
$expiration = (time() + (2*24*60*60)) * 1000; 
$java = isset($_GET['java']) ? filter_var($_GET['java'], FILTER_SANITIZE_STRING ) : "false"; 

// check if java is ready, then execute the chip updater
if( $java == "ready" ){

    // load jnlp template
    $dom = new DOMdocument('1.0', 'utf-8');
    $dom-&gt;formatOutput = true;

    $dom-&gt;load('template.jnlp.php');
    $node = $dom-&gt;getElementsByTagName("application-desc")-&gt;item(0); // locate the start place and prep for insertion

    // map name attribute
    $var = $dom-&gt;createElement("argument", base64_encode($map_name)); // place a new argument tag and place an encoded name there
    $node-&gt;appendChild($var);

    // map version attribute
    $var = $dom-&gt;createElement("argument", base64_encode($map_version)); // place a new argument tag and place an encoded version there
    $node-&gt;appendChild($var);

    // set expiration attribute
    $var = $dom-&gt;createElement("argument", base64_encode($expiration)); // place a new argument tag and place an encoded expiration time there
    $node-&gt;appendChild($var);

    // output jnlp mime header and force download=
    header("Content-Type: application/x-java-jnlp-file");
    header("Content-Disposition: attachment; filename=update.jnlp");
    //header("Content-Type: text/xml");

    // output xml content
    echo $dom-&gt;saveXML();
    //echo $dom-&gt;saveXML($node);

    } // end
    else{
        echo &lt;&lt;&lt;EOD
        &lt;?xml version="1.0" encoding="UTF-8"?&gt;
        &lt;html&gt;
            &lt;head&gt;&lt;/head&gt;
            &lt;body&gt;
                &lt;script src="http://www.java.com/js/deployJava.js" type="text/javascript"&gt;&lt;!-- // --&gt;&lt;/script&gt;
                &lt;script type="text/javascript"&gt;
                    if (deployJava.versionCheck('1.6') || deployJava.versionCheck('1.7')) {
                        var str = location.href;
                        var z = str.replace("https://","http://");
                        var n = z.replace("?download=1","");
                        var url = n + "&amp;java=ready";

                        window.location = url; // possibly replace with = ((location.href).replace("?download=1","")) + "&amp;java=ready"

                    }
                    else{
                        alert("We have detected that you either do not have Java installed, or that it may be an older version. We are redirecting you to the Java download site where you will be able to install the newest version of Java. &lt;!!! -- If the window does not load, you may need to allow popups from our site. Please watch for a popup warning and allow it to then relaunch! -- !!!&gt;");
                        var url="./update2.php";
                        window.open(url);
                        window.history.back();
                    }
                &lt;/script&gt;
            &lt;/body&gt;
        &lt;/html&gt;

EOD;
    }
</code></pre>

<p><strong>Note:</strong> I understand there are some bad practices, such as using $_GET() instead of $_POST(), which will take time to fix due to the way the system was set-up. I also understand the DOM object is grabbing everything off my web page, which is causing the error if I use this code on the same page of my system's framework. This code was developed before I came aboard the company, and I am trying to see if I can tweak it to make it work, or if a different method needs to be taken. </p>

<p>I appreciate any input you can share. Thanks!</p>
