Current Position:Home > Download and Upload using applet

Download and Upload using applet

Update:10-11Source: network consolidation
Advertisement
hi everyone,
i tried to develop an applet that can handle upload and download file from server to client and vice versa.
is there anyone can help me?
Please help.
thank you for replies.

The Best Answer

Advertisement
You need to sign your applet and the user needs to trust this signature in order for the
applet to read from the local filesystem and or connect to a server other than the one the
applet came from.
http://forum.java.sun.com/thread.jsp?forum=63&thread=524815
second post
Here is some code that will upload (both msjvm and sun jre) but I never really finished
it. Note that if you use the applet with msjvm the client has to adjust java security in IE
import java.awt.*;
import java.net.*;
import java.io.*;
public class srvHead extends java.applet.Applet implements Runnable{
     String c = "";
     public srvHead(){
          new Thread(this).start();
     public void init(){
//          new Thread(this).start();
     public void run(){
          try{
// run this as an application first, when it works than make an applet of it
               URL u = new URL("http://localhost:101/test");
               URLConnection c = u.openConnection();
               // post multipart data
               c.setDoOutput(true);
               c.setDoInput(true);
               c.setUseCaches(false);
               // set some request headers
               c.setRequestProperty("Connection", "Keep-Alive");
// TODO: get codebase of the this (the applet) to use for referer
               c.setRequestProperty("HTTP_REFERER", "http://applet.getcodebase");
               c.setRequestProperty("Content-Type", "multipart/form-data; boundary=****4353");
               DataOutputStream dstream = new DataOutputStream(c.getOutputStream());
// write content to the server, begin with the tag that says a content element is comming
               dstream.writeBytes("--****4353\r\n");
// discribe the content, (in this case it's a file)
               dstream.writeBytes("Content-Disposition: form-data; name=\"myfile\"; filename=\"C:\\myFile.wav\"\r\nContent-Type: application/octet-stream\r\n\r\n");
// open a file
               String title = "Frame Title";
               Frame frame = new Frame("Select a file");
               FileDialog fd = new FileDialog(frame);
               frame.setSize(400, 400);
               fd.show();
               System.out.println(fd.getDirectory() + fd.getFile());
               File f = new File(fd.getDirectory() + fd.getFile());
               FileInputStream fi = new FileInputStream(f);
// keep reading 1000 bytes from the file
               byte[] bt = new byte[1000];
               int cnt = fi.read(bt);
               while(cnt==bt.length){
                    dstream.write(bt,0,cnt);
                    cnt = fi.read(bt);
// send the last bit to the server
               dstream.write(bt,0,cnt);
// now close the file and let the web server know this is the end of this form part
               dstream.writeBytes("\r\n--****4353\r\n");
// send a form part named TargetURL with the value: /IntranetContent/TelephoneGuide/Upload/
               dstream.writeBytes("Content-Disposition: form-data; name=\"TargetURL\"\r\n\r\n");
               dstream.writeBytes("/IntranetContent/TelephoneGuide/Upload/");
// let the web server know this is the end of this form part
               dstream.writeBytes("\r\n--****4353\r\n");
// send a form part named redirectURL with the value: http://none/none
               dstream.writeBytes("Content-Disposition: form-data; name=\"redirectURL\"\r\n\r\n");
               dstream.writeBytes("http://none/none");
// this is the last information part of the multi part request, close the request
// close the multipart form request
               dstream.writeBytes("\r\n--****4353--\r\n\r\n");
               dstream.flush();
               dstream.close();
               fi.close();
               try{
                    DataInputStream in =
                         new DataInputStream(
                              new BufferedInputStream(c.getInputStream()));
                    String sIn = in.readLine();
                    boolean b = true;
// TODO: this will loop forever unless you make sure your server page
// sends a last line like "I am done"
// than you can do wile(sIn.compareTo("I am done")!=0){
                    while(sIn!=null){
                         if(sIn!=null){
                              System.out.println(sIn);
                         sIn = in.readLine();
               }catch(Exception e){
                    e.printStackTrace();
          }catch(Exception e){
               e.printStackTrace();
     public static void main(String[] args) {
               new srvHead();
}
  • Download and Upload using applet Update:10-11

    hi everyone, i tried to develop an applet that can handle upload and download file from server to client and vice versa. is there anyone can help me? Please help. thank you for replies.You need to sign your applet and the user needs to trust this sig

  • File Uploader Java Applet cannot be run Update:11-30

    I have a website that I need to upload PDFs to, but since ugrading to Lion, I cannot do it any more.  I have downloaded the separte Java app, but it still does not work. This is the error message I get: File Uploader Java Applet cannot be run. Make s

  • After hours of back-up, downloading and uploading...I am now updated with all the latest Mac software. However, I no longer have access to Excel and Word. Is there a way I can access my documents in either of those? Help, please. Update:10-11

    After hours of back-up, downloading and uploading...I am now updated with all the latest Mac software. However, I no longer have access to Excel and Word. Is there a way I can access my documents in either of those? Help, please.If you have older ver

  • PO header attachment download and upload Update:10-11

    Hi All, I have requirement to download the attachments attached at Purchase Orders(PO) header level . And then from the downloaded file , I further want to upload it to another target system. I have already uploaded the PO at target system but header

  • File download and Upload using SOAP in Oracle ADF Update:10-11

    Hi Gurus, I have a requirement of Uploading and downloading a file on a location. It is for uploading and downloading an Attachments for a user. I have a table in my jspx page for showing the current attachments and an option to upload a new attachme

  • Hierarchy download and upload Update:10-11

    Hi experts, i want to download hierarchies from production bw to development bw. pls explain me the procedure how to do. as i understand hierarchies will be in the r/3 system. then how do i download them and upload them to the required box in bw. is

  • Function module to choose the file for download and upload Update:10-11

    what is the function module to choose the file for download and upload  for presentation server. give me with examplePlease search in SCN. This has been discussed so many times.Read other 2 answers

  • Download and Upload Status/other utilities in one offline file Update:10-11

    Hi, Is it possible to download or upload the GUI statuses? Also, I am curious if there is any utility by which I can find all the related technical objects for one report/utility? e.g. when i try to copy objects from one system to another(which are n

  • Download and Upload smartform in 4.6c Update:10-11

    I have the requirement to download and upload the smartforms in 4.6c. I need the help, which standard function module will solve the problem. Thanks . Vinayak.Hi, Use Transaction "Smartforms" -->Enter Smartform Name -> Utilities> Downlo

  • Download and Upload(!) ABAP-Source and DDIC-Objects? Update:10-11

    Hi, is there a standard transaction or third party tool to download and upload(!!) ABAP-Source (function modules, function groups, module pools, reports...) and DDIC-Objects (tables, structures, data elements) to a local file system? In terms of uplo