exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jprintlist); 의 예시가 많이 나오더라.
하지만 setParameter는 내가 지금 사용하고 있는 6.5.1버전에서는 이미 사라진 함수.
exporter.setExporterInput(new SimpleExporterInput(jasperPrintList)); 형식으로 사용해주어야 한다.
각 함수에 필요한 타입은 이러하다.
exporter.setExporterInput(ExporterInput exporterInput);
ExporterInput exporterInput = SimpleExporterInput.getInstance(ArrayList<JasperPrint> jasperPrintList);
JasperPrint jasperPrint = JasperFillManager.getInstance(jasperReportsContext).fill(JasperReport jasperReport, new HashMap(), new JRMapCollectionDataSource(ArrayList<Map<String,Object>>);
jsp에서 출력하고 있기 때문에 모든 변수에 컬렉션과 타입 선언을 정확하게 초기화해주어 사용해야한다.
Map paramMap = new HashMap<String,Object>();
paramMap = (Map)request.getAttribute("detaillist");
//각 페이지에 필요한 resultSet를 arrayList로 담고,
//각 arrayList를 페이지별로 detail0 , detail1.. 의 키를 설정하여 HashMap으로 묶어 responce에 담아 리턴함.
List paramList = new ArrayList<Map<String,Object>>(); //dataSource에 들어갈 arrayList
try{
List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();
for(int i = 0 ; i < paramMap.size(); i++){
paramList = (List)paramMap.get("detail"+i);
dataSource = new JRMapCollectionDataSource(paramList);
//jasper report 파일의 리스트를 담음.
jasperReport = JasperCompileManager
.compileReport(jasperPath + "/" + report_name + "_" + i + ".jrxml");
jasperPrint = JasperFillManager.getInstance(jasperReportsContext)
.fill(jasperReport, new HashMap(), dataSource);
jasperPrintList.add(jasperPrint);
}
JRExporter exporter = new JRPdfExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
//jasperPrintList를 exportInput에 담음.
OutputStream output = new FileOutputStream(new File("저장할 파일 위치"));
exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, output);
exporter.exportReport();
}catch(Exception e){
e.printStackTrace();
}