JASPERREPORT生成报表
nt对象,和设置导出时的session */
public class ReportUtils {
private HttpServletReuest reuest;
private HttpServletResponse response;
private HttpSession session;
public ReportUtils(HttpServletReuest reuest, HttpServletResponse response) {
this.reuest = reuest;
this.session = reuest.getSession();
this.response = response;
}
/**
* 获得JasperPrint对象;自定义填充报表时的parameter和dataSource. 参数说明和动态表头的用法参考上一方法 */
public JasperPrintgetJasperPrint(String filePath, Map parameter,JRDataSourcedataSource) throws JRException { JasperReportjasperReport = null;
try {
jasperReport = (JasperReport) JRLoader.loadObject(filePath);
return JasperFillManager.fillReport(jasperReport, parameter,dataSource);
} catch (JRException e) {
e.printStackTrace();
}
return null;
}
/**
* 获得JasperPrint对象;自定义填充报表时的parameter和connection
*/
public JasperPrintgetJasperPrint(String filePath, Map parameter,Connection conn) throws JRException { JasperReportjasperReport = null;
try {
jasperReport = (JasperReport) JRLoader.loadObject(filePath);
return JasperFillManager.fillReport(jasperReport, parameter,conn);
} catch (JRException e) {
e.printStackTrace();
}
return null;
}
/**
* 通过传入List类型数据源获取JasperPrint实例
*/
public JasperPrintgetPrintWithBeanList(String filePath, Map parameter,List list) throws JRException { JRDataSourcedataSource = new JRBeanCollectionDataSource(list);
return getJasperPrint(filePath, parameter, dataSource);
}
/**
* 传入类型,获取输出器
*
* @paramdocType
* @return
*/
public JRAbstractExportergetJRExporter(DocTypedocType) {
JRAbstractExporter exporter = null;
switch (docType) {
case PDF:
exp