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