views:

670

answers:

1

Here's I want to do, I want to upload a file that will be processed by a servlet. I would use Apache Commons - File Upload to handle the file to be uploaded.

I've seen the gmail-like AJAX file upload, where there would be a hidden iframe that would later be populated with a javascript to stop showing the upload image or displaying a message that the upload is succesful. However, this uses PHP, where the php file to handle the file upload would include the javascript inside the iframe.

My question is, how would I do this in Java using servlets, without resorting to JSP and imitating the above implementation on PHP. I don't even know if this is possible, so please guide me on a good implementation (without external libraries except for commons fileupload).

Note: I am aware that there are libraries out there that could do this easily, but I first want to know how this happens, how this is possible, and to dirty my hands and learn this.

Edit: Just to add, I would use the streaming API of Apache-Commons FileUpload

+1  A: 

It is exactly the same.

The client makes an HTTP request to the server (by submitting a form).

The server responds with some HTML (which links to or embeds some JavaScript).

Switching from PHP to Java is just a drop in replacement. You don't need to change any of the JavaScript. The user guide tells you how to set it up.

David Dorward
Could you tell me how to embed HTML to a redirect without JSP?
mives
Why would a redirect be involved? The servelet just needs to output a text/html response.
David Dorward
A-Hah! That just shows I'm really new to this AJAX thing. Was accustomed to redirecting to servlets and JSP. :) Thanks!
mives