0

I have signed applet, I want to download any kind of file from the server and place it in the file system using the applet.

Please give some pointer.

Thanks in advance.

Roman C
  • 49,761
  • 33
  • 66
  • 176
kkchaitu
  • 631
  • 2
  • 5
  • 24

2 Answers2

0

You'll have to write servlet for this. Because servlets can access to server local file system and get files you want for your applet :) Make bound like a

applet <-servlet<-server

Good luck

user592704
  • 3,674
  • 11
  • 70
  • 107
  • What does 'make bound like' mean? – user207421 Oct 10 '11 at 04:20
  • in this case bound means that servlet should send output stream to your applet :) – user592704 Oct 10 '11 at 16:19
  • ;-) is fine but could we stick to the standard terminology please? – user207421 Oct 10 '11 at 20:55
  • It is not a standard technology (not a framework or something). You'll have to write two programms as servlet (as a back-end) and applet (as its front-end app). Next you'll have to combine applet+servlet with IO interaction. In your case you want to make a download applet so you need your servlet to provide output stream right to your applet using http :) It is a commonly used thing especially in applets which should work with db source because they all use servlet for this... – user592704 Oct 12 '11 at 03:09
  • So search in these directions as "applet" then "servlet" and then "applet and database". So basically you need to know how to write applets and how to write servlets; rest thing it is just applet and setvlet interaction with http and nothing more :) – user592704 Oct 12 '11 at 03:12
  • Reading a TCP connection is standard technology. It is not necessary to invent terminology like 'make bounded' to describe it. 'Connect' covers it adequately. – user207421 Oct 12 '11 at 23:44
0

The applet need to be signed to access the file system.

 public String downloadFile(final String filename) {
    return (String)AccessController.doPrivileged(new PrivilegedAction(){
        public Object run() {       
          try {
                // downloadURL is the server URL say http://localhost/downloads
                // filename is a file want to download from the server 
                // localpath is the path you want to download in the file system
                URL finalURL = new URL(downloadURL + filename);
                ReadableByteChannel rbc = Channels.newChannel(finalURL.openStream());
                FileOutputStream fos = new FileOutputStream("/"+localpath.replace("\\","/") +  filename);
                fos.getChannel().transferFrom(rbc, 0, 1 << 24);
                fos.close();
            return "true";
          }catch (ConnectException ce) {
              e.printStackTrace();
              return "false";
          } 
          catch (Exception e) {
            e.printStackTrace();
            return "false";
          }
        }
      });
}
kkchaitu
  • 631
  • 2
  • 5
  • 24