views:

19

answers:

1

I have a scenario where i have to upload a zip file on a button click , I can't use forms for that, so I need to handle it either by calling the servlet using document.location.href or through AJAX, after uploading the file I need to extract it on the server. So someone can please tell me what will be possible approach for that.

A: 

Javascript cannot access the local disk file system nor alter the <input type="file"> field, so it stops here. It's a very good security restriction, it would otherwise have been a huge security hole (one would otherwise be able to create an invisible form with a prefilled file field, e.g. c:/passwords.txt, and submit it during onload of the window).

Either just let the user select the file to upload, or embed a little client application in the webpage (e.g. Applet, Silverlight, etc). It only needs some $$$ to get them digitally signed so that you can get it to run on the client without that the client needs to face security warning dialogues because it's attempting to unaskingly access the local disk file system.


For the file upload extraction part, I can warmly recommend Apache Commons FileUpload. Also see this answer with code examples.

BalusC