How to upload folder in web application

天涯浪子 提交于 2019-12-22 21:12:10

问题


I am developing simple application using JSF with richfaces. I want to upload folder(select folder only).

I tried, t:inputFileUpload and rich:fileUpload.
but both components are support file only. Not support select folder.

Is possible to select folder.

Help Me. thanks in advance


回答1:


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.



来源:https://stackoverflow.com/questions/7844356/how-to-upload-folder-in-web-application

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