Using an Error Page
| To display a helpful message in the event of an error, use JFile's
ErrorURL parameter.
The ErrorURL parameter specifies the URL of a page to display when an error
occurs. When you set the ErrorURL parameter, JFile will add an error code
to the URL's query string. For example, if ErrorURL is set to http://localhost/jfilescripts/errorpage.asp,
JFile will send the query string http://localhost/jfilescripts/errorpage.asp?jfile_errorcode=number.
|
 |
| Recursive Directory Upload |
|
Exercise 5: Creating an Error Page
- If you created the physical and virtual JFileScripts directories in
a previous lesson, go to Step 4. If you did not create the directories,
go to Step 2.
- Create a directory called JFileScripts.
- Create a virtual directory called JFileScripts and map it to the physical JFileScripts you created in Step 2:
- Open the Internet Information Services (IIS) explorer.
- Right-click Default Web Site.
- Select New -> Virtual Directory.
- For Alias, enter JFileScripts.
- Browse to the JFileScripts directory you created in step 1.
- Check "Read" and "Run scripts."
- Click "Finish."
- 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).
- 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.
- Create an ASP script containing the following line. Name it errorpage.asp and save it in the directory
JFileScripts.
SoftArtisans JFile error <% =Request.QueryString("jfile_errorcode") %> occurred.
- Create an HTML script containing the following lines. Name the file errorupload.htm and save it in
the directory JFileScripts.
<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 ErrorURL parameter contains the URL of a file to open when an error occurs. -->
<PARAM name="ErrorURL" value="http://localhost/jfilescripts/errorpage.asp">
<!-- 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. To see your error page, enter an
invalid file name. -->
<PARAM name="FileName1" value="c:\invalidname.ext">
</APPLET>
- To run the script, open the browser, and enter the URL http://localhost/jfilescripts/errorupload.htm.
Understanding the Script
Errorpage.asp
When you assign a URL to the ErrorURL parameter (as you do in errorupload.htm), JFile will add an error code
to the URL's query string. In our case, the ErrorURL with JFile's error code would be,
http://localhost/jfilescripts/errorpage.asp?jfile_errorcode=number
Errorpage.asp retrieves JFile's error code from the request's query string and
displays an error message containing the code, as follows,
SoftArtisans JFile error <%=Request.QueryString("jfile_errorcode")%> occurred.
The following table lists JFile's error codes and their definitions.
| Name |
Value |
Description |
| Cancel_Error |
100 |
The user hit the cancel button or closed the status window during a transfer. |
| General_Receive_Error |
200 |
A failure occurred while receiving a
response from the server. The connection with server may have been reset. |
| General_Send_Error |
300 |
Error occurred while sending the request to the server. The connection with
the server may have been broken. There may be a malfunctioning proxy server
preventing a large transfer. There may be insufficient privileges on the
remote system. |
| Https_Socket_Not_Supported_Error |
301 |
SSL is currently not supported when using Sockets. |
| File_Not_Found_Error |
302 |
There are two possible causes: 1) the PostURL is invalid or doesn't
exist, or 2) the local preset filename does not exist. |
| Enable_Permissions_Error |
303 |
This occurs only with Netscape, if user has not been granted the required
permissions. |
| Version_Expired_Error |
400 |
The trial version has expired. |
Errorupload.htm
- The APPLET tag adds JFile's UploadClient applet to your web page. We assigned values to several APPLET
attributes:
- The Cabbase parameter specifies the cab file containing the Java applet. Filetransfer.cab contains JFile's Java
class files for Internet Explorer.
- The ErrorURL parameter contains the URL of a file to open when an error occurs. JFile will automatically
add an error code to the URL's query string. You can retrieve the error code to create an error message, as demonstrated in
errorpage.asp.
- The PostURL parameter specifies the URL to which the file will be posted, http://localhost/jfilescripts/formresp.asp.
Formresp.asp uses SoftArtisans FileUp to process the upload.
- The FileNameN parameter specifies a file to transfer. Enter an invalid file name to open the ErrorURL
page.