Search code examples
javajavascriptappletjnlp

Javascript args on parameters in runApplet method


I need to put arguments in a Applet but i must use the deployJava library js.

My code is:

var attributes = {id : "GenericDiv", code: namespace, width:200, height:200}; 
var parameters = {args: "{'eventHandler':'fingerprint'}", jnlp_href:'/xxx.jnlp' }; 
var version = '1.6' ; 
deployJava.runApplet(attributes, parameters, version); 

But the code doesn't work, the javascript haven't attachs the fingerprint.

Thanks all ;)


Solution

  • Specifying an Applet's Input Parameters

    You can specify an applet's input parameters in the applet's Java Network Launch Protocol (JNLP) file or in the element of the <applet> tag. It is usually better to specify the parameters in the applet's JNLP file so that the parameters can be supplied consistently even if the applet is deployed on multiple web pages. If the applet's parameters will vary by web page, then you should specify the parameters in the <parameter> element of the <applet> tag.

    The example on that page shows two different ways to define the applet parameters:

    Consider an applet that takes three parameters. The paramStr and paramInt parameters are specified in the applet's JNLP file, applettakesparams.jnlp.

    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp spec="1.0+" codebase="" href="">
        <!-- ... -->
        <applet-desc
             name="Applet Takes Params"
             main-class="AppletTakesParams"
             width="800"
             height="50">
                 <param name="paramStr"
                     value="someString"/>
                 <param name="paramInt" value="22"/>
         </applet-desc>
         <!-- ... -->
    </jnlp>
    

    The paramOutsideJNLPFile parameter is specified in the parameters variable passed to the Deployment Toolkit script's runApplet function in AppletPage.html.

    <html>
      <head>
        <title>Applet Takes Params</title>
        <meta http-equiv="Content-Type" content="text/html;
            charset=windows-1252">
      </head>
      <body>
        <h1>Applet Takes Params</h1>
    
        <script
          src="https://www.java.com/js/deployJava.js"></script>
        <script>
            var attributes = { code:'AppletTakesParams.class',
                archive:'applet_AppletWithParameters.jar',
                width:800, height:50 };
            var parameters = {jnlp_href: 'applettakesparams.jnlp',
                paramOutsideJNLPFile: 'fooOutsideJNLP' };
            deployJava.runApplet(attributes, parameters, '1.7');
        </script>
    
      </body>
    </html>
    

    Source Defining and Using Applet Parameters.