JSF+iReport報表無法在LINUX SERVER產出問題
1.JSF的頁面的AJAX需為FALSE,Primefaces的預設為TRUE,需把它設為FALSE,才會有動作
2.若報表有SHOW圖檔,在iReport設計時需把圖檔的Path指定到傳入的參數名稱去,然後java程式需在報表OUTPUT前把路徑PUT到參數中去,這樣DEPLOY到LINUX SERVER去後才不會發生錯誤無法show出報表的問題。
public void doPrint() {
ServletOutputStream servletOutputStream = null;
InputStream reportStream = null;
System.out.println("doPrint *****************");
//以下為抓beans資料程式
try {
FacesContext fc = FacesContext.getCurrentInstance();
JRDataSource ds = new JRBeanCollectionDataSource(detailDataLists);
HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
reportStream = fc.getExternalContext().getResourceAsStream("/rpt/deliveryEN.jasper");
servletOutputStream = response.getOutputStream();
fc.responseComplete();
response.setContentType("application/pdf");
HashMap parameters = new HashMap();
parameters.put("deliveryNo", mainData.getDeliveryNo());//出貨單號
parameters.put("deliveryDate", mainData.getDeliveryDate());//出貨日期
parameters.put("custNo", mainData.getCustNo());//客戶編號
parameters.put("custAddress", mainData.getCustAddress1());//客戶地址
parameters.put("orderNo", mainData.getOrderNo());//訂單號碼
parameters.put("contractNo", mainData.getContractNo());//合約號碼
//logo圖檔Path
String logoimage = fc.getExternalContext().getRealPath("/resources/images/fuco.jpg");
parameters.put("logoPath", logoimage);
//加總數量及重量
parameters.put("totalQty", totalQty);//總數量
parameters.put("totalWeight", totalWeight);//總重量
JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameters, ds);
} catch (Exception e) {
logger.error(null, e);
} finally {
//DbUtils.closeQuietly(conn);
try {
reportStream.close();
servletOutputStream.flush();
servletOutputStream.close();
} catch (Exception e) {
logger.error(null, e);
}
}
//以上為抓beans資料程式
}
2.若報表有SHOW圖檔,在iReport設計時需把圖檔的Path指定到傳入的參數名稱去,然後java程式需在報表OUTPUT前把路徑PUT到參數中去,這樣DEPLOY到LINUX SERVER去後才不會發生錯誤無法show出報表的問題。
public void doPrint() {
ServletOutputStream servletOutputStream = null;
InputStream reportStream = null;
System.out.println("doPrint *****************");
//以下為抓beans資料程式
try {
FacesContext fc = FacesContext.getCurrentInstance();
JRDataSource ds = new JRBeanCollectionDataSource(detailDataLists);
HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
reportStream = fc.getExternalContext().getResourceAsStream("/rpt/deliveryEN.jasper");
servletOutputStream = response.getOutputStream();
fc.responseComplete();
response.setContentType("application/pdf");
HashMap parameters = new HashMap();
parameters.put("deliveryNo", mainData.getDeliveryNo());//出貨單號
parameters.put("deliveryDate", mainData.getDeliveryDate());//出貨日期
parameters.put("custNo", mainData.getCustNo());//客戶編號
parameters.put("custAddress", mainData.getCustAddress1());//客戶地址
parameters.put("orderNo", mainData.getOrderNo());//訂單號碼
parameters.put("contractNo", mainData.getContractNo());//合約號碼
//logo圖檔Path
String logoimage = fc.getExternalContext().getRealPath("/resources/images/fuco.jpg");
parameters.put("logoPath", logoimage);
//加總數量及重量
parameters.put("totalQty", totalQty);//總數量
parameters.put("totalWeight", totalWeight);//總重量
JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameters, ds);
} catch (Exception e) {
logger.error(null, e);
} finally {
//DbUtils.closeQuietly(conn);
try {
reportStream.close();
servletOutputStream.flush();
servletOutputStream.close();
} catch (Exception e) {
logger.error(null, e);
}
}
//以上為抓beans資料程式
}
留言
張貼留言