jsp中的下载选项窗口
我需要在 jsp 中为用户提供一个选项来选择一个文件夹
,他可以在其中保存/下载文件。请帮助我。
文本 input="file"
将提供文件选择器,但我需要 目录选择器
I need to give an option to user in jsp to choose a folder
where he can save/download a file. Please help me on the same.
the text input="file"
will give the file chooser but i need the directory chooser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
HTTP 不允许您指定(服务器端)文件下载到的位置 - 这不是 jsp 特有的事情。
如果您需要这样做,那么您需要提供一个可嵌入的应用程序(javascript、java、flash、vbscript...),该应用程序允许在浏览器沙箱之外运行,并实现其自己的网络客户端来检索文件。这远非理想的解决方案。
您可以通过内容处置标头强制下载使用特定名称。
..但那是用于上传 - 不是下载。
HTTP doesn't allow you to specify (server side) where a file is downloaded to - this is not a jsp specific thing.
If you need to this then you'd need to provide an embedable application (javascript, java, flash, vbscript...) which is allowed to operate outside the browser sandbox and implements its own network client for retrieving the file. Which is far from an ideal solution.
You can force the download to use a specific name via the content disposition header.
..but that's for uploads - not downloads.
您
无法
使用 JSP/Servlet 在客户端计算机上设置下载文件的文件夹位置。如果您想添加文件夹选择器功能,那么您必须开发一个小程序
。您可以使用JFileChooser
来允许用户选择一个文件夹,并使用java.net.URL
和java.net.URLConnection
来下载文件。You
can't
set folder location at client machine of downloaded file using JSP/Servlet. If you want to add folder chooser feature then you have to develop anapplet
. You may useJFileChooser
to allow user to select a folder andjava.net.URL
andjava.net.URLConnection
to download a file.大多数浏览器会自动下载浏览器不渲染的文件,所以它只是一个链接......!例如,如果它是 zip 文件,只需将其添加为代码中的任何旧“链接”即可。当用户单击时,将启动下载/保存对话框......
“保存/下载”功能是客户端问题 - 请记住网络开发人员的工作是提供内容 - 浏览器决定如何处理内容。
Most browsers will automatically download a file that the browser doesn't render, so it's just a link...! For example, if it's a zip file, just add it as any old "a link" in your code. When the user clicks , the download/save dialog will be launched ....
The "save/download" feature is a client issue -remember the web developers job is to provide content- it's the browser that decides how to deal with the content.
关键是
Content-Disposition
标头。它的值必须设置为attachment
才能强制另存为对话框。您可以在 servlet 中完成这项工作。只需让您的链接 URL 指向文件 servlet,如下所示然后,在文件 servlet 中(将上面的示例映射到
/fileservlet/*
的 URL 模式),执行以下操作:请参阅另外:
The key is the
Content-Disposition
header. Its value has to be set toattachment
to force a Save As dialogue. You can do this job in a servlet. Just let your link URL point to a file servlet like soThen, in the file servlet, which is for the above example to be mapped on an URL pattern of
/fileservlet/*
, do the following:See also: