0 Replies Latest reply on Dec 13, 2007 1:18 PM by Phil Haigh

    changing response headers to modify filename for excel

    Phil Haigh Novice


      I'm trying to open a report in Excel, with a specified dynamic filename

      I have an xhtml page that spits out simple tabulated data. On viewing that page ID I call a method from pages.xml that does this:

      String fileName="Charity_Report"+i+".xls";
      HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
      response.setHeader("Content-Disposition","attachment;filename=\"" + fileName + "\"");

      This works... the report is generated correctly, and with the right filename etc. However, intermittently, the spreadsheet that opens will have both the report that just ran, and the previous one in it! (I should mention there are several different report pages, with different filenames - set up exactly the same as above).

      It appears perhaps the response is not closing or something like that??

      I tried this:

      // TODO This is such a hack it's untrue (closes response after 5s)

      but although it doesn't seem to do any harm, it doesn't fix the intermittent problem.

      any ideas?