Scripting the Applet Using Client-Side JavaScript

The previous lessons demonstrated manipulating JFile's upload and download applets using HTML <param> tags. You can also control JFile in JavaScript. JFile's numerous JavaScript methods are defined in the UploadClient Applet and DownloadClient Applet sections of the Programmer's Reference.

The following exercise hides JFile's ready-made file list and transfer status windows. This allows you to create your own user interface. We will create a very simple interface: an upload button. When clicked, the button will call JFile's startUpload method.

JavaScript methods are case-sensitive.
Using JFile's startUpload method

Exercise 3: Scripting the Applet Using Client-Side JavaScript

  1. If you created the physical and virtual JFileScripts directories in A Simple Upload or A Simple Download, go to Step 4. If you did not create the directories, go to Step 2.

  2. Create a directory called JFileScripts.

  3. Create a virtual directory called JFileScripts and map it to the physical JFileScripts you created in Step 2:

    1. Open the Internet Information Services (IIS) explorer.
    2. Right-click Default Web Site.
    3. Select New -> Virtual Directory.
    4. For Alias, enter JFileScripts.
    5. Browse to the JFileScripts directory you created in step 1.
    6. Check "Read" and "Run scripts."
    7. Click "Finish."

  4. Copy filetransfer.jar (for Netscape) and/or filetransfer.cab (for Internet Explorer) to the directory JFileScripts. These files are in JFile's installation directory (by default, C:\Program Files\SoftArtisans\JFile).

  5. Copy formresp.asp to the directory JFileScripts. Formresp.asp is a server-side upload processing script that you will find in JFile's Samples\Upload\Simple directory (installed by default at C:\Program Files\SoftArtisans\JFile). Formresp.asp uses SoftArtisans FileUp to process the upload.

  6. Create an HTML script containing the following lines. Name the script scriptapplet.htm and save it in your JFileScripts directory.
    <APPLET codebase="/JFileScripts" code="softartisans.filetransfer.UploadClient.class" 
    height="0" width="0" mayscript archive="filetransfer.jar" name="fileupload">
    
    	<!-- The Cabbase parameter specifies the cab file containing the applet. -->
    	<PARAM name="cabbase" value="filetransfer.cab">	
    	
    	<!-- The PostURL parameter specifies the URL to which the file will be posted. -->	
    	<PARAM name="PostURL" value="http://localhost/jfilescripts/formresp.asp">
    	
    	<!-- The FileName# parameter specifies a file to transfer.  When uploading more than one file, use 
    	"FileName1," "FileName2," etc. -->
    	<PARAM name="Filename1" value="c:\boot.ini">
    	
    	<!-- The HideFileList and HideTransferStatus parameters hide JFile's file list and transfer status windows, 
    	allowing the programmer to control the user interface. -->
    	<PARAM name="HideFileList" value="1">
    	<PARAM name="HideTransferStatus" value="1">
    </APPLET>
    
    <!-- Create a button that calls JFile's startUpload method. -->
    <input type="button" value="Upload c:\boot.ini" onclick="document.fileupload.startUpload();">
    

    Understanding the Script




    Previous Page Next Page