通知用户文件正在下载 servlet 中生成
我有一个下载 servlet,它生成一个包含一些文件的 ZIP,其中一个文件相当大,然后在响应中发送生成的文件以供下载。
问题是生成过程相当大,在生成 de ZIP 的步骤和下载步骤(当用户看到下载对话框时)之间可能会过去很多秒甚至一分钟。所以我想无论如何通知用户该文件正在生成。
我正在考虑的解决方案是执行多个请求,一个请求打开一个模式窗口,通知用户并在其中,然后自动对在临时位置生成文件的操作执行另一个请求,然后当请求结束时,另一个关闭窗口(窗口必须自动关闭),然后向 servlet 请求下载上一步中生成的文件。
如果有人理解我想要做什么,我希望是否存在更好、更干净的解决方案。
I have a download servlet which generates a ZIP with some files, one of them pretty big, and then sends the generated file in the response for download.
The problem is that the generating process is pretty big, and between the step of the generation of de ZIP and the download step (when the user see the download dialog) many seconds or even a minute could pass. So I would like to inform the user by anyway that the file is being generated.
The solution I'm thinking about is doing several requests, one for open a modal window which informs the user and inside this, then do another request automatically to an action which generates the file in a temp location and then, when the request ends, another one which closes the window (the window must be closed automatically) and then request to the download servlet the generated file in the last step.
If somebody understands what I'm trying to do, I would like if exists a better and cleaner solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以触发一个 ajax 请求,该请求将启动生成过程,然后其他 ajax 请求轮询服务器是否文件已准备好。如果是 - 将浏览器的位置更改为该文件。否则,显示“正在加载”消息/图像/..
You can fire an ajax request which will start the generation process, and then other ajax requests to poll the server if the file is ready. If yes - change the location of the browser to the file. Otherwise, show a "loading" message/image/..