servlets - I am uploading file with DiskFileItemFactory.But file is not uploading using Java -


i trying upload file using java web application using diskfileitemfactory.but problem not getting file.it shows empty array in iteration.

iter.size() 0. see below of code.

public modelandview upload( modelmap model, httpsession session, httpservletrequest request, httpservletresponse resp) throws ioexception, servletexception, fileuploadexception { if (servletfileupload.ismultipartcontent(request)) {      system.out.println("file available"); }  boolean ismultipart = servletfileupload.ismultipartcontent(request); if (ismultipart) {     //  resourceimpl resource = new resourceimpl();     try {         //create factory disk-based file items         fileitemfactory factory = new diskfileitemfactory();         servletfileupload upload = new servletfileupload(factory);         list items = upload.parserequest(request);         system.out.println(items.size());         iterator iter = items.iterator();         while (iter.hasnext()) {              fileitem item = (fileitem) iter.next();         }      } catch (exception e) {      } } 

my form is;

 <form method="post" action="/dropbox/upload.html" enctype="multipart/form-data">      select file upload: <input type="file" name="uploadfile" />      <br/><br/>      <input type="submit" value="upload" />  </form> 

where doing wrong. plaese me. thanq.

you should try each. well.

if (servletfileupload.ismultipartcontent(request)) {      try {         list<fileitem> multipart = new servletfileupload(new diskfileitemfactory()).parserequest(request);          (fileitem item : multipart) {              if (!item.isformfield()) {                  filename = new file(item.getname()).getname();                 folder = "path";                 file file = new file(folder);                  if (!file.exists()) {                     file.mkdir();                  }             }              item.write(new file(folder + "/" + filename));         }     } } 

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -