java - File upload from another computer -


i have problem regarding on uploading file. when upload files myself(localhost) works when let other people in same network upload file gives me error:

(the system cannot find path specified) @ java.io.fileinputstream.open(native method) @ java.io.fileinputstream.<init>(fileinputstream.java:120) @ sources.uploadaip.actions.uploadaction.processrequest(uploadaction.java:49) 

here actual code:

public class uploadaction extends abstractappaction {    public boolean processrequest(httpservlet servlet, httpservletrequest request,    httpservletresponse response)    {      try{          properties appproperties = getappproperties();          string dbmap = appproperties.getproperty("dbmap");          db db = getdbconnection(dbmap);           string mydirectory = "c:\\tmp";          string uploadedfile = request.getparameter("filename");          system.out.println("srcfile: " +mydirectory);          system.out.println("file: " +uploadedfile);          string errormessage = "";           servletcontext sc       = servlet.getservletcontext();          string filename         = stringutil.stringreplace(uploadedfile,"\\","\\");          int                   = filename.lastindexof("\\");          if (i > 0) {                filename   = filename.substring(i+1);           }           file srcfile            = new file(uploadedfile);          file targetdirectory    = new file(mydirectory);          string dirname          = stringutil.stringreplace(targetdirectory.tostring() ,"\\","\\");          system.out.println("directory name:" +dirname);          file destfile           = new file(dirname+"\\"+filename);          system.out.println(destfile);          system.out.println("here parent directory: " +targetdirectory);              if(!targetdirectory.exists()){               targetdirectory.mkdirs();          }          inputstream instream;          outputstream outstream;          try{              instream = new fileinputstream(srcfile);          outstream = new fileoutputstream(destfile);              byte[] buffer = new byte[4096];          int length;          //copy file content in bytes          while ((length = instream.read(buffer)) > 0){                   outstream.write(buffer, 0, length);          }          outstream.close();          }catch(exception e){              e.printstacktrace();          }          filename = stringutil.stringreplace(uploadedfile, "\\", "\\");            int u = filename.lastindexof("\\");           if (u > 0)           {             filename = filename.substring(i + 1);           }            if (!dirname.endswith("\\"))           {            dirname = dirname + "\\";           }            file f = new file(dirname);           string uploaddir = dirname;           system.out.println("uploaddirectory" +uploaddir);        } catch (exception ex) {         request.setattribute("message", ex.tostring());         ex.printstacktrace();      }     return (true); } 

}

your code assumes file being uploaded present on same local machine, isnt true, since receiving uploads local network.

this why works on local machine, not across network.

to upload file, need multipart form , servlet correctly handles multipart request.

this tutorial should you:

http://www.avajava.com/tutorials/lessons/how-do-i-upload-a-file-to-a-servlet.html


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -