|
[x]
Posted via EE Mobile
|
|
| Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
|
|
|
|
Asked by mathewstcom in Java Server Faces (JSF)
hi i need to download pdf file from jsf richfaces application
following is my code but it doesnt initiate download but it ll write content of pdf into page, ofc not proporely its writing there binary data of pdf not proper content
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
|
HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpServletResponse resp = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
resp.reset();
String offerId = req.getParameter("id");
Long id = new Long(offerId);
Dokument dokument = dokumentSvc.findLoaded(id);
String contentType = TypDokumentu.PDF == dokument.getTyp()?"application/pdf":"text/html";
String extension = TypDokumentu.PDF == dokument.getTyp()?".pdf":".html";
try {
if (dokument == null)
showNA(resp);
else {
resp.setContentType("application/force-download");
resp.setContentLength(dokument.getData().getData().length);
resp.setHeader("Content-Disposition",
"download; filename=\"preview.pdf\"");
OutputStream ou;
ou = resp.getOutputStream();
ou.write(dokument.getData().getData());
ou.flush();
ou.close();
}
} catch(Exception e) {
}
FacesContext.getCurrentInstance().responseComplete();
|
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625