如何在RemoteServiceServlet中生成文件并将其发送给用户? [英] How Can I generate a file in RemoteServiceServlet and send it to a user?

查看:80
本文介绍了如何在RemoteServiceServlet中生成文件并将其发送给用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我可以禁用RemoteServiceServlet响应序列化或使用返回ServletOutputStram的方法定义RemoteService接口?我希望不要在任何数据库中保存请求,以便在另一个请求中处理它。 解决方案

如果您想提供下载到用户,你可以这样做:


  1. 编写另一个servlet,通过ServletResponse写出文件内容

  2. 确保你有一个二进制头文件,并在那里提供文件名。

  3. 在你的客户端中,制作一个< 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:

  1. Write another servlet which simply writes out the file content through the ServletResponse
  2. Make sure you have a binary header and provide the filename in there, too.
  3. In your client, make an <iframe ..> (The widget class for this is Frame) 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆