开发者

uploading zip file to server using servlets [duplicate]

This question already has answers here: How can I upload files to a server using JSP/Servlet and Ajax? (4 answers) Closed 6 years ago.

I have a scena开发者_StackOverflowrio 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜