How Can I generate a file in RemoteServiceServlet and send it to a user?

那年仲夏 提交于 2020-01-16 19:19:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7086114/how-can-i-generate-a-file-in-remoteserviceservlet-and-send-it-to-a-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!