报表输出及print

public abstract class ReportBaseAction extends ActionSupport {
private static final long serialVersionUID = 190881665780129568L;

protected List rptData;
private String rtpFmt;
protected String rptName;

protected String rptFileName;

private ReportService reportService;

protected abstract void getReportResult();

public String goRPT() throws Exception {
compileRpt(JasperReportConstants.FORMAT_HTML);
return rtpFmt;
}

public String goPrint() throws Exception {
String pathPrefix = ServletActionContext.getServletContext()
.getRealPath("/jasper/");
JasperPrint jasperPrint = null;
JasperReport jasperReport = null;

compileRpt(ReportService.FORMAT_PRINT);
//datasource
JRDataSource dataSource = new JRBeanCollectionDataSource(this.getRptData()) ;
//load report template
jasperReport = (JasperReport)JRLoader.loadObject(pathPrefix+"/"+this.getRptFileName()) ;
Map<String,String> param = new HashMap<String,String>();
//load report data
jasperPrint = JasperFillManager.fillReport(jasperReport, param, dataSource) ;

JasperPrintManager.printReport(jasperPrint, true) ;
return "success";
}

private void compileRpt(String targetType) throws Exception {
getReportResult();
String pathPrefix = ServletActionContext.getServletContext()
.getRealPath("/jasper/");
this.setRptFileName(reportService.compileJasper(pathPrefix, this.getRptName(),targetType));
// String reportSource;
// reportSource = ServletActionContext.getServletContext().getRealPath(
// "/jasper/" + rptName + ".jrxml");
// File parent = new File(reportSource).getParentFile();ֻ�Ǻ�׺��ͬ����
// JasperCompileManager.compileReportToFile(reportSource, new File(parent,
// rptName + ".jasper").getAbsolutePath());
}

public String getRtpFmt() {
return rtpFmt;
}

public void setRtpFmt(String rtpFmt) {
this.rtpFmt = rtpFmt;
}

public String getRptName() {
return rptName;
}

public void setRptName(String rptName) {
this.rptName = rptName;
}

public ReportService getReportService() {
return reportService;
}

public void setReportService(ReportService reportService) {
this.reportService = reportService;
}

public List getRptData() {
return rptData;
}

public void setRptData(List rptData) {
this.rptData = rptData;
}

public String getRptFileName() {
return rptFileName;
}

public void setRptFileName(String rptFileName) {
this.rptFileName = rptFileName;
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值