• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Uploading Image file from client to the server

 
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am tryign to upload an image file from client machine to the server for that i am using Commons FileUpload from Apache. the html i have designed is



and the servlet Fileupload takes the multipart content from the request and saves the file successfully on the server.

But here as i am clicking the button upload the current page where the Image gets uploaded is replaced by a blank page which is normally the feature of a submit button. i want to stay in the same page and upload the image can anybody suggest me how do i do this.

I tried using Ajax to call the servlet.. being able to stay on same page using Ajax the file multipart content is not passed to servlet and file do not get uploaded.

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not setting anything to be submitted to the server and not all browsers support uploading files via Ajax. Use the jQuery plugin to do it.

Eric
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even when i submit the form directly without using AJAX, i was not setting anything to be submitted to the servlet .. it was directly getting the data as described in the link http://commons.apache.org/fileupload/using.html .... instead of directly submitting the form i was trying to do it from Ajax ... The servlet was getting called but the file along with the content was not getting streamed.

I also used JQuery to call the servelt as $.post('FileUpload',{},function(data){});

Still the servlet gets called up but teh file is not getting saved on the server.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read some docs: https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest

Eric
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THe above link describes the method on Mozilla.. i am tryign to execute the given examples in IE... as my application has to run on IE ... and it gives me errors saying FormData is undefined... i googled and found that FormData element is supported by Mozilla not by IE.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And as I stated before, YOU CAN NOT USE THE XMLHTTPREQUEST OBJECT TO UPLOAD A FILE WITH ALL BROWSERS. Look on the web, there are solutions already made that will upload a file asynchronously using a hidden iframe.

Eric
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"rt ssum", please check your private messages for an important administrative matter. Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic