Logging on to an HP3000 host

In this example, an HP terminal session applet is embedded in the browser window, and JavaScript is used to log on to the host computer. Four <form> fields on the web page are used to get the user's name, group, account, and password before performing the logon.

To use this example, you must change the hostURL parameter in the <applet> tag below to a host appropriate for your network.

<html>
<head>
<title>Sample Logon Script for HP (JavaScript)</title>
<script language="JavaScript">
<!--
    var uname, group, account, pword;
    var api = null;

    /*
       The jsapiInitialized function is called by Reflection
       when it has finished its initialization. Reflection
       passes the function a reference to the JavaScript API.
    */
    function jsapiInitialized( jsapi )
    {
       api = jsapi; 
    }

    /*
       This is the main function that performs the logon tasks.
    */
    function handleLogonButton()
    {
        // Validate the username and password.
        if ( validateInputs() )
        {
            doConnect();
        }
    }

    /*
       This function checks for a group, account, and password, and 
       if any of these is not present, displays an alert message.
    */
    function validateInputs()
    {
        uname = document.LogonForm.Username.value;
        pword = document.LogonForm.Password.value;
        group = document.LogonForm.Group.value;
        account = document.LogonForm.Account.value;

        // For the host in this example, a username is not required, 
        // but a group and account are.
        if ( group == "" )
        {
            alert( "You must enter a Group to log on!" );
            document.LogonForm.Group.focus();
            return false;
        }
        if ( account == "" )
        {
            alert( "You must enter an Account to log on!" );
            document.LogonForm.Account.focus();
            return false;
        }
        
        if ( pword == "" )
        {
            alert( "You must enter a Password to log on!" );
            document.LogonForm.Password.focus();
            return false;
        }
        return true;
    }
    
    /*
       This function starts the actual logon tasks. It determines if the session
       is connected, and if so, calls the function that finds the Username and 
       Password prompts on the display and transmits the user's data.
    */
    function doConnect()
    {
        // If there's no connection, try to connect.
        if ( !api.isConnected() )
        {
            self.status = "Connecting...";
            api.connect();
        }
        else
        {
            alert( "You're already connected!" );
            return;
        }

        // Wait 5 seconds for the MPE XL prompt to appear in the datacomm stream.
        // By using the HP-specific waitForHostPrompt method, the wait will be 
        // for the string "MPE XL" plus the DC1 host prompt character.
        self.status = "Waiting for host prompt.";
        if ( !api.waitForHostPrompt( "MPE XL:", 5000 ) )
        {
            alert( "Unable to find MPE XL prompt. The script will stop, " + 
                   "but you may continue manually." );
            return;
        }
        
        // MPE XL prompt was found, so transmit the username, group, and
        // account, followed by a carriage return. The octal representation
        // of the carriage return character--which is decimal 13--is used. You
        // can also use the carriage return symbol \r or the hex value
        // \x0D. You CANNOT use the decimal value 13, because this will be
        // converted to a string and appended to the username.
        var helloStr = "hello ";
        if ( uname != "" )
        {
            helloStr += uname + ",";
        }
        helloStr += group + "." + account;
        api.transmitString( helloStr + "\015" );
        
        // Wait 5 seconds for the Password prompt.
        self.status = "Waiting for Password prompt.";
        if ( !api.waitForHostPrompt( "Password:", 5000 ) )
        {
             alert( "Unable to find Password prompt. The script will stop, " + 
                   "but you can try completing the logon manually." );
            return;
        }

        // Password prompt was found, so transmit the user's password,
        // followed by a carriage return. As above, the octal
        // representation of the carriage return character is used.
        api.transmitString( pword + "\015" );
        
        // Done with logon, so display final status message, and set
        // focus to the terminal display.
        self.status = "Ready to proceed.";
        api.requestDisplayFocus();
    }
// -->
</script>
</head>
<body>
<h1>Reflection for the Web -- HP Logon</h1>
<p>
<!--
   Create a basic HP applet on the page, but don't connect until
   the user fills in the username, group, account, and password 
   information. A default group (DOCS) and account (WRITERS) are 
   already in the text fields, so the minimum information the
   user needs to supply is the password, because the username is
   optional for the host in this example.
   
   To use this example, change the hostURL parameter to one 
   appropriate for your network, and change the default group and
   account in the form fields.
-->
<applet mayscript name="HP"
        codebase="./ex/"
        code="com.wrq.rweb.Launcher.class"
        width="640" height="400"
        archive="Launcher.jar">
    <param name="hostURL" value="nsvt://techpubs">
    <param name="autoconnect" value="false">
    <param name="frame" value="false">
    <param name="launcher.sessions" value="HP">
    <param name="preloadJSAPI" value="true">
</applet>
</p>
<!--
   Use <form> items to accept the Username, Group, Account, and Password, 
   and to create a Logon button.
-->
<form name="LogonForm">
<p>Username: <input type="text" name="Username" default size="25">
Group: <input type="text" name="Group" value="Docs" default size="25">
Account: <input type="text" name="Account" value="Writers" default size="25"></p>
<p>Password: <input type="password" name="Password" size="25">
<input type="button" name="logon" value="Logon" onClick="handleLogonButton()"></p>
</form>
</body>
</html>