How to transfer a file from xPages?

I am trying to transfer a file from the file system to the browser and cannot make it work correctly. I have 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 get an error like this on the 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 "response.getOutputStream ()" method throws this error, so I cannot get the output stream to work. Does anyone have any experience? I'm just trying to implement a download service so that I can transfer files from the server file system back to the browser.

+4
source share
1 answer

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

For more help, see the links below:

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

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

+6
source

Source: https://habr.com/ru/post/1398635/


All Articles