Sunil,
      Here's the code for uploading files

//Example
//c:\projects\java HTTPPostClient c:\adm2fp\SS00_2000_08_10_01.xml


import java.net.*;
import java.io.*;

public class HTTPPostClient
{

  /*----------------------------------------------------------------------------
  * usage
  *---------------------------------------------------------------------------*/
  private static void usage()
  {
    System.out.println("Usage: HTTPostClient file");
  }

  /*----------------------------------------------------------------------------
  * main
  *---------------------------------------------------------------------------*/
  public static void main(String args[])
  {
    try
    {

      if (args.length != 1)
      {
        usage();
        return;
      }

      // Get connection to Upload Servlet
      URL theURL = new URL("http://servername/servlet/UploadServlet");
      //UploadServlet is a servlet that reads incoming file and copies
      //onto the server

      HttpURLConnection theConnection =
        (HttpURLConnection)theURL.openConnection();
      theConnection.setRequestProperty("Content-Type", "text/xml");
      theConnection.setRequestMethod("POST");
      theConnection.setDoOutput(true);
      PrintWriter out = new PrintWriter(theConnection.getOutputStream());

      // Read XML File
      String fileContents = "";
      String line = null;
      FileReader f1 = new FileReader(args[0]);
      BufferedReader theReader = new BufferedReader(f1);

      // Send each line to Servlet
      while ((line = theReader.readLine()) != null)
      {
        System.out.println(line);
        out.println(line);
      }
      out.close();
      System.out.println("Data Written");

      // Get Response
      System.out.println("Response: ");
      String inputLine;
      InputStream in = theConnection.getInputStream();
      BufferedReader responseReader =
        new BufferedReader(new InputStreamReader(in));
      while ((inputLine = responseReader.readLine()) != null)
      {
        System.out.println(inputLine);
      }
      in.close();

    }
    catch (Exception e)
    {
      System.out.println("Exception Caught:\n" + e);
    }
  }
}

Hope that helps
Santosh







Sunil Roy <[EMAIL PROTECTED]> on 10/02/2000 03:58:29 PM

Please respond to A mailing list about Java Server Pages specification and
      reference <[EMAIL PROTECTED]>

To:   [EMAIL PROTECTED]
cc:    (bcc: Santosh Daryani/IT/Aon Consulting)

Subject:  " UPLOAD of FILES  "  in JSP/SERVLETS



Dear JSp Gurus,

Is their any site giving the sourcecode for
" UPLOAD of FILES "  in JSP/SERVLETS."

Thanks in anticipation

Bye
Sunil Roy

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to