How to upload folder in web application

落爺英雄遲暮 提交于 2019-12-06 06:00:40

The standard HTML <input type="file"> already can't do it. So the <t:inputFileUpload> which just renders exactly that HTML element is out of question. Also, Flash also doesn't allow folder selection due to security restrictions. So, the <rich:fileUpload> is also out of question.

Your best bet is using a Java applet which uses the Swing JFileChooser which allows you to select a directory. You could then write some Java code which collects all files in that folder and uploads it to the server side by URLConnection or HttpClient. Then you just embed that applet in your JSF page the usual plain HTML/JS way. Instead of reinventing the applet wheel, you could also go for an existing 3rd party applet like JumpLoader or JUpload. Both support uploading whole directories.

Finally, you've to integrate it in combination with a plain vanilla servlet utilizing Apache Commons FileUpload to parse the file upload requests from the applet. To let it interact with JSF, you could store some unique attribute in the session or use a session scoped JSF managed bean which is also available in the servlet. I'm not sure if JumpLoader or JUpload supports it, but it's technically possible to let the applet update the page by JavaScript (which allows for applet-JSF communication by JS/Ajax).

No, there comes no existing 3rd party JSF component to mind which does the same job.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!