★ wanayoo — archive 1999 http://developer.iplanet.com/docs/examples/java/file_uploading.htmlNouvelle recherche | Portail wanayoo
iPlanet

You are here:  Home > Developers > Sample Code > Java > Java Sample Code
Java Sample Code
 iPlanet Developers


Developer Program
  Membership
  One-to-One Support
  Newsgroups
  Member Services

Developer Publications
  View Source
  Developer News

Documentation
  Technical Manuals
  White Papers
  TechNotes
  Sample Code
  FAQs
  Books

Technologies
  CSS
  DOM
  CORBA
  Directory & LDAP
  Dynamic HTML
  Java
  JavaScript
  Linux
  RDF
  Security
  SSJS
  XML
  XUL

Developer Downloads
  Tools & SDKs
  Patches

iPlanet Products
  Technical Resources










spacer
How to Perform a File Upload Using Server-Side Java

This is an HTML file which allows the user to select a file on the client's hard drive. This file needs to be uploaded to the server.

There are three ways of doing this: -

  1. CGI.
  2. NSAPI Service function upload file.
  3. Using Server Side Java.

The Java code is the implementation of the Server Side Java Applet. This can be done on both Enterprise and Fast Track servers.



// Here is a server side java applet which gets the file from the client.
// The way it demonstrates it received the file from the client (meaning the file 
// upload was successful) it just spits out the file back to the browser.
// Start of Server Side Java Applet code
 
 import netscape.server.applet.HttpApplet;
 import netscape.server.applet.ServerApplet;
 
 import java.io.*;
 import java.net.Socket;
 import java.net.InetAddress;
 import java.lang.IndexOutOfBoundsException;
 import java.util.Hashtable;
 import java.util.Enumeration;
 
 class FormApplet extends HttpApplet {
 
     public void run() throws Exception {
     Hashtable formdata;
     int x;
     PrintStream out = getOutputStream();
 
     InputStream is = getInputStream();
     DataInputStream di = new DataInputStream(is);
 
     if (returnNormalResponse("text/html")) {
             out.print(header);
 
            PrintStream POut = getOutputStream();
            String line;
 
            while ((line = di.readLine()) != null)
               POut.println(line);
            out.print(trailer);
         }
    }
    private static final String header = "<h1>Form results</h1>\n<ul>\n";
    private static final String trailer = "</ul>\n";
 }

// This is the HTML file calling the server side applet
// What this HTML file does is allows a user to select a file which 
// can be uploaded to the server

 
 <HTML>
 <HEAD>
 <TITLE>
 DevEdge Request Form
 </TITLE>
 </HEAD>
 <BODY>
 <H2>
 Incident Submit Form
 </H2>
 <FORM  ENCTYPE="multipart/form-data"
 ACTION="/old?u=http%3A%2F%2Fgraphite%2Fserver-java%2FFormApplet%2F&y=1999" METHOD=POST>
 <TABLE BORDER=2 CELLPADDING=1>
 <TR>
 <TD> File Name </TD>
 <TD COLSPAN=3><INPUT TYPE=FILE NAME="uploadfile"></TD>
 </TR>
 </TABLE>
 <CENTER>
 <INPUT TYPE="submit" VALUE="Submit"> <INPUT TYPE="reset" VALUE="Clear
 Entries">
 </CENTER>
 </FORM>
 </BODY>
 </HTML>



Related Reading:


Any sample code included above is provided for your use on an "AS IS" basis, under the Netscape License Agreement - Terms of Use

spacer spacer


                                                       
iPlanet International | Year 2000 | Site Map | Feedback
Products | Solutions | Support | Services | Download | About Us | Developer
© 2000 Sun-Netscape Alliance. All Rights Reserved  Privacy Policy