如何在网络应用程序中上传文件夹
我正在使用 JSF 和 richfaces 开发简单的应用程序。我想上传文件夹(仅选择文件夹)。
我尝试了t:inputFileUpload和rich:fileUpload。
但这两个组件都只是支持文件。不支持选择文件夹。
可以选择文件夹。
帮我。 提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标准 HTML
已经无法做到这一点。因此,
只渲染该 HTML 元素是没有问题的。此外,由于安全限制,Flash 也不允许选择文件夹。因此,
也是没有问题的。最好的选择是使用使用 Swing < 的 Java 小程序code>JFileChooser 它允许您选择一个目录。然后,您可以编写一些 Java 代码,收集该文件夹中的所有文件并通过
URLConnection
或 HttpClient。然后,您只需以通常的纯 HTML/JS 方式将该小程序嵌入到 JSF 页面中即可。您也可以选择现有的第 3 方小程序,例如 JumpLoader 或 JUpload。两者都支持上传整个目录。最后,您必须将其与普通的 servlet 结合使用 Apache Commons FileUpload 来解析来自小程序的文件上传请求。为了让它与 JSF 交互,您可以在会话中存储一些唯一的属性,或者使用会话范围的 JSF 托管 bean,该 bean 也可在 servlet 中使用。我不确定 JumpLoader 或 JUpload 是否支持它,但技术上可以让 applet 通过 JavaScript 更新页面(这允许通过 JS/Ajax 进行 applet-JSF 通信)。
不,没有现有的第 3 方 JSF 组件可以完成相同的工作。
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 byURLConnection
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.