public String pdf(){
query 後的datasource
this.query();
用來裝相關pars用的
Map pars = new HashMap();
pars.put("title", "jimmy title 測試");
FacesContext fc = FacesContext.getCurrentInstance();
fc.responseComplete();這個method沒處理會發生Servlet response already use stream, Writer not possible
透過 FacesContext 來取得 HttpServletResponse
HttpServletResponse res = (HttpServletResponse) fc.getExternalContext().getResponse();
透過 FacesContext 來取得 ServletContext
ServletContext servletContext = (ServletContext) fc.getExternalContext().getContext();
String path = servletContext.getRealPath("/report/test.jasper");
File jasperFile = new File(path);
try {
ReportUtils.createPdf(res, jasperFile, pars, this.userlist, 1);
} catch (Exception ex) {
}
return null;
}
沒有留言:
張貼留言