如何在RemoteServiceServlet中生成文件并将其发送给用户? [英] How Can I generate a file in RemoteServiceServlet and send it to a user?
本文介绍了如何在RemoteServiceServlet中生成文件并将其发送给用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果您想提供下载到用户,你可以这样做:
- 编写另一个servlet,通过ServletResponse写出文件内容
- 确保你有一个二进制头文件,并在那里提供文件名。
- 在你的客户端中,制作一个
< iframe ..>
(这个widget类是Frame
),并将它的url指向新的servlet。
由于二进制标题,您的浏览器现在将向用户提供另存为弹出窗口。这应该是全部。
Maybe I can disable RemoteServiceServlet response serialization or define RemoteService interface with method that returns ServletOutputStram? I would like not to save request in any database to file to process it in another request.
解决方案
If you want to provide a download to the user, you can do it like this:
- Write another servlet which simply writes out the file content through the ServletResponse
- Make sure you have a binary header and provide the filename in there, too.
- In your client, make an
<iframe ..>
(The widget class for this isFrame
) and point its url to your new servlet.
Due to the binary header your browser will now provide the user with a Save as.. popup. That should be all.
这篇关于如何在RemoteServiceServlet中生成文件并将其发送给用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文