I am planning on having asynchronous file uploads. That is the file should be uploaded to a jsp or servlet and return something to the html/jsp page without reloading the original page. It should happen like an AJAX call. Is there any way to do it in AJAX or any other way to do it.
3 Answers
The two common approaches are to submit the form to an invisible iframe, or to use a Flash control such as YUI Uploader. You could also use Java instead of Flash, but this has a narrower install base.
(Shame about the layout table in the first example)

- 21,988
- 13
- 81
- 109

- 914,110
- 126
- 1,211
- 1,335
-
2This answer is not today's way to do it. Iframes, Java, flash are not web standards. – pjotr_dolphin Mar 19 '19 at 17:23
-
1@pjotr_dolphin — *None* of the answers here are how to do it today. This question is from a decade ago. – Quentin Mar 19 '19 at 18:52
-
sure, that is why I downvoted it and made a comment. – pjotr_dolphin Mar 20 '19 at 08:34
The latest dwr (http://directwebremoting.org/dwr/index.html) has ajax file uploads, complete with examples and nice stuff for users (like progress indicators and such).
It looks pretty nifty and dwr is fairly easy to use in general so this will be pretty good as well.

- 7,280
- 4
- 35
- 43
I don't believe AJAX can handle file uploads but this can be achieved with libraries that leverage flash. Another advantage of the flash implementation is the ability to do multiple files at once (like gmail).
SWFUpload is a good start : http://www.swfupload.org/documentation
jQuery and some of the other libraries have plugins that leverage SWFUpload. On my last project we used SWFUpload and Java without a problem.
Also helpful and worth looking into is Apache's FileUpload : http://commons.apache.org/fileupload/index.html

- 2,302
- 1
- 17
- 24
-
It is indeed possible to do asynchronous file uploads without Flash; e.g. gmail. – DanM Nov 23 '09 at 16:45
-
2
-
12Note from the future: Flash is almost non existent due to mobile phones popularity. See this answer: http://stackoverflow.com/questions/2320069/jquery-ajax-file-upload – hitautodestruct Apr 26 '16 at 11:32