aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Uploading Image file from client to the server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Uploading Image file from client to the server" Watch "Uploading Image file from client to the server" New topic
Author

Uploading Image file from client to the server

carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

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.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jun 23, 2007
Posts: 300

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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Read some docs: https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest

Eric
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

"rt ssum", please check your private messages for an important administrative matter. Thanks.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Uploading Image file from client to the server