• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Uploading Image file from client to the server

 
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"rt ssum", please check your private messages for an important administrative matter. Thanks.
 
permaculture is largely about replacing oil with people. And one tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!