jsf 中的文件保存对话框
我正在尝试以 Excel 格式导出数据库的结果集。我正在使用 JSF 开发一个 Web 应用程序。所以我需要的是,当用户单击页面中的“导出”按钮时,必须打开一个文件保存对话框,供用户选择目录路径和文件名称。
当在文件对话框中单击“保存”时,我需要根据用户输入的名称和路径将整个结果集写入 Excel 工作表。
但我找不到文件保存对话框以及如何在 JSF 中使用它。我正在使用 jdeveloper 进行开发。
请给我建议一个解决方案。
I am trying to export the result set of the DB in a excel format. And I am developing a web application using JSF. So what i need is that when the user clicks on the EXPORT button in my page , then a file save dialog has to open for the user to choose the directory path and the name for the file.
And when the save is clicked in the file dialog then i need to write the whole result set to the excel sheet with the mentioned name and path as per users input.
But i couldnt find the file save dialog and how to use the same with JSF. And I am using jdeveloper for the development .
Please suggest me a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关键是
Content-Disposition
响应标头,您需要将其设置为attachment
。这将在浏览器中强制显示“另存为”对话框。您需要做的就是设置正确的Content-Type
响应标头(以便浏览器知道它是什么类型的文件)并将原始文件的内容写入响应正文。因此,总结一下(假设您使用 Apache POI 生成 Excel 工作表):
The key is the
Content-Disposition
response header which you need to set toattachment
. This will force a Save As dialogue in the browser. All you need to do along this is to set a properContent-Type
response header as well (so that the browser know what type of file it is) and to write the raw file's content to the response body.So, summarized (assuming that you're using Apache POI to generate the Excel sheet):