Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Jaxson Brown   on Jul 14 In Java Category.

  
Question Answered By: Husani Chalthoum    on Jul 14

Please tring following code:

 public  void download() {
try {
 attachment  attach = attachments.get(attachmentRowId);
byte[] binaryData = attach.getFile();

HttpServletResponse response  = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("fileName", "FILE_NAME");
response.setContentType(contentType);
response.setContentLength(binaryData.length);
response.setHeader("Content- Disposition", "attachment; filename= \"" + attach.getFileName() + "." + attach.getFileType() + "\"");
ServletOutputStream out = response.getOutputStream();
out.write(binaryData);
out.flush();
out.close();
response.flushBuffer();
FacesContext.getCurrentInstance().responseComplete();

}
catch (Exception e) {
e.printStackTrace();
}
}

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Problem with Download in jsf Or get search suggestion and latest updates.


Tagged: