【问题标题】:How to stream file from xPages?如何从 xPages 流式传输文件?
【发布时间】:2012-02-27 16:19:37
【问题描述】:

我正在尝试将文件从文件系统流式传输到浏览器,但无法使其正常工作。我有一个 render=false 的 xpage,在 afterRenderResponse 上我有以下代码:

XspHttpServletResponse  response = (XspHttpServletResponse) getFacesContext().getExternalContext().getResponse();

response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename=demofile.exe");

File file = new File("path to file");
FileInputStream fileIn = new FileInputStream(file);
ServletOutputStream out = response.getOutputStream();
etc. .....

现在,当我尝试打开 xpage 时,我在控制台上收到如下错误消息:

java.lang.IllegalStateException: Can't get an OutputStream while a Writer is already in use
       at com.ibm.xsp.webapp.XspHttpServletResponse.getOutputStream(XspHttpServletResponse.java:548)

“response.getOutputStream()”方法会引发此类错误,因此我无法使输出流正常工作。有没有人有这方面的经验?我只是尝试实现下载服务,以便将文件从服务器文件系统流式传输回浏览器。

【问题讨论】:

  • 您能否发布您的 xagent 的完整源代码。提前致谢!

标签: xpages


【解决方案1】:

您可以在 beforeRenderResponse 中调用 facesContext.getOutputStream() 而不是在 afterRenderResponse 中。

更多帮助请参考以下链接:

http://www.wissel.net/blog/d6plinks/SHWL-8BYMW8

http://www.wissel.net/blog/d6plinks/shwl-7mgfbn

【讨论】:

  • beforeRenderResponse 事件解决了这个问题!!!下次我会更仔细地阅读文档......
猜你喜欢
  • 2012-09-09
  • 1970-01-01
  • 2017-11-21
  • 2015-08-22
  • 1970-01-01
  • 2015-05-14
  • 2014-08-26
  • 2011-05-22
  • 1970-01-01
相关资源
最近更新 更多