I'm using Apache POI to generate document with .docx extension. I set the file name in the header response (HttpServletResponse), but the browser saves a file with same name at the end of my URL, example:
URL in my browser is: localhost:8080/MyProject/mypage.jsf, the name of the downloaded file is mypage.jsf, ignoring the name set in the header (HttpServletResponse). If I edit the file extension for docx, content is OK.
Here's the code:
private void generateDocument() throws IOException{
XWPFDocument document = new XWPFDocument();
//load document here
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) facesContext
.getExternalContext().getResponse();
response.reset();
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
ServletOutputStream out = response.getOutputStream();
document.write(out);
response.setHeader("Content-Disposition",
"attachment; filename=my_document.docx");
facesContext.responseComplete();
}
Ps. I'm using Richfaces 4
Thanks