Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem trying to send file to browser in JSF
    primarykey
    data
    text
    <p>Hi I've tried two different techniques for sending a file to a browser(making the user download a file). I've tried an example from myfaces wikipage</p> <pre><code>FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getResponse(); int read = 0; byte[] bytes = new byte[1024]; String fileName = "test.txt"; response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\""); OutputStream os = null; StringBuffer stringBuffer1 = new StringBuffer("Java Forums rock"); ByteArrayInputStream bis1; try { bis1 = new ByteArrayInputStream(stringBuffer1.toString().getBytes("UTF-8")); os = response.getOutputStream(); while ((read = bis1.read(bytes)) != -1) { os.write(bytes, 0, read); } os.flush(); os.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } FacesContext.getCurrentInstance().responseComplete(); </code></pre> <p>I have also tried using a component named fileDownload from PrimeFaces. Both give the same result:</p> <p>I get a response from the server, the response contains text that should be in the file. The header is a follows:</p> <pre><code>X-Powered-By Servlet/3.0, JSF/2.0 Server GlassFish v3 Content-Disposition attachment;filename="test.txt" Content-Type text/plain Transfer-Encoding chunked Date Thu, 20 May 2010 06:30:20 GMT </code></pre> <p>To me this looks correct but for some reason I don't get to download the file, I just get this response in firebug.</p> <p>Does anyone have any idea?, could it be a serversetting problem? I using glassfish 3</p> <p>Thanks / Stefan</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload