如何在Web应用程序中上传文件夹 [英] How to upload folder in web application

查看:112
本文介绍了如何在Web应用程序中上传文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Richfaces的JSF开发简单的应用程序.我要上传文件夹(仅选择文件夹).

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

我尝试了 t:inputFileUpload rich:fileUpload .
但是这两个组件仅是支持文件.不支持选择文件夹.

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

可以选择文件夹.

帮帮我. 预先感谢

推荐答案

标准HTML <input type="file">已经无法做到.因此,恰好呈现HTML元素的<t:inputFileUpload>毫无疑问.另外,由于安全限制,Flash也不允许选择文件夹.因此,<rich:fileUpload>也毫无疑问.

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.

您最好的选择是使用Java小程序,该小程序使用Swing HttpClient .然后,您只需以普通的普通HTML/JS方式将该小程序嵌入到JSF页面中即可.除了重新设计applet轮外,您还可以使用现有的第三方方applet,例如 JumpLoader

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.

最后,您必须使用 Apache Commons FileUpload 将其与普通香草Servlet集成在一起解析来自applet的文件上传请求.为了使其与JSF进行交互,您可以在会话中存储一些唯一的属性,也可以使用会话范围内的JSF托管Bean,该Bean在servlet中也可用.我不确定JumpLoader或JUpload是否支持它,但是从技术上讲,可以让小程序通过JavaScript更新页面(这允许JS/Ajax通过applet-JSF进行通信).

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).

不,我不认为现有的第三方JSF组件可以完成相同的工作.

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

这篇关于如何在Web应用程序中上传文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆