How to stream file from xPages?

血红的双手。 提交于 2019-12-10 17:33:11

问题


I'm trying to stream the file from file system to browser and cant get it to work properly. I have a xpage with rendered=false and on afterRenderResponse I have the following code:

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. .....

Now when I try to open xpage I'm getting the error message as this on console:

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)

The method 'response.getOutputStream()' raises such error so I cant get output stream to work. Is there anyone having experience with this? I'm simply trying to implement the download service so I can stream files from server file system back to browser.


回答1:


You can call the facesContext.getOutputStream() in the beforeRenderResponse and NOT from afterRenderResponse.

Refer to the below links for more help:

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

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



来源:https://stackoverflow.com/questions/9468352/how-to-stream-file-from-xpages

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