六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 101|回复: 0

报表输出及print

[复制链接]

升级  1.33%

12

主题

12

主题

12

主题

秀才

Rank: 2

积分
52
 楼主| 发表于 2013-2-7 20:58:57 | 显示全部楼层 |阅读模式
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;
}

}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表