Buenas tardes :
Mi problema es el siguiente; deseo crear un reporte y tengo el siguiente codigo:
@SuppressWarnings("unchecked")
public void ejecutaReporte(){
File file = new File("D:/temp/");
String template ="reportTrafico";
//String nomFile = sc.getRealPath("/reportes/reportTrafico.jasper");
Map params = new HashMap();
params.put("anio",anio);
params.put("trimestre",trimestre);
params.put("tipoEnvio","E");
printReport(
"P", // P for PDF
params,
new StringBuffer("/WEB-INF/reports/").append(template)
.append(".jrxml").toString(),
template);
}
public Connection getConnection(){
SqlDBConn conn = new SqlDBConn();
Connection cnx = conn.getConnection();
return cnx;
}
@SuppressWarnings("unchecked")
public final boolean printReport(String format, Map params,
String template, String attachmentName) {
Connection c = getConnection();
try {
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext ext = context.getExternalContext();
InputStream fis = ext.getResourceAsStream(template);
JasperReport jasperReport = JasperCompileManager.compileReport(fis);
params.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.FALSE);
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, params, c);
HttpServletResponse resp = (HttpServletResponse) ext
.getResponse();
resp.setContentType("application/pdf");
String filename = new StringBuffer(attachmentName).append(
".pdf").toString();
resp.addHeader("Content-Disposition", "inline; filename="
+ filename);
JasperExportManager.exportReportToPdfStream(jasper Print, resp
.getOutputStream());
/*
JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, params, c);
HttpServletResponse resp = (HttpServletResponse) ext.getResponse();
resp.setContentType("application/pdf");
String filename = new StringBuffer(attachmentName).append(".pdf").toStri ng();
resp.addHeader("Content-Disposition", "inline; filename=" + filename);
JasperExportManager.exportReportToPdfStream(jasper Print, resp.getOutputStream());
JRExporter exporter = null;
exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_P RINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_S TREAM, resp.getOutputStream());
*/
/*
else if ("C".equals(format)) {
params.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, params, c);
HttpServletResponse resp = (HttpServletResponse) ext
.getResponse();
resp.setContentType("text/plain");
String filename = new StringBuffer(attachmentName).append(
".csv").toString();
resp.setHeader("Content-Disposition", "inline;filename="
+ filename);
JRCsvExporter exporter = new JRCsvExporter();
exporter.setParameter(JRCsvExporterParameter.JASPE R_PRINT,
jasperPrint);
exporter.setParameter(JRCsvExporterParameter.OUTPU T_STREAM,
resp.getOutputStream());
exporter.setParameter(JRExporterParameter.IGNORE_P AGE_MARGINS,
Boolean.TRUE);
exporter.exportReport();
}
else if ("E".equals(format)) {
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, params, c);
HttpServletResponse resp = (HttpServletResponse) ext
.getResponse();
resp.setContentType("application/vnd.ms-excel");
String filename = new StringBuffer(attachmentName).append(
".xls").toString();
resp.setHeader("Content-Disposition", "inline;filename="
+ filename);
JExcelApiExporter exporterXLS = new JExcelApiExporter();
exporterXLS.setParameter(
JRXlsExporterParameter.JASPER_PRINT,
jasperPrint);
// exporterXLS.setParameter(Boolean.TRUE);
exporterXLS.setParameter(
JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,
Boolean.FALSE);
exporterXLS.setParameter(
JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWE EN_ROWS,
Boolean.TRUE);
exporterXLS.setParameter(
JRXlsExporterParameter
.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,
Boolean.TRUE);
// exporterXLS.setParameter(
// JRXlsExporterParameter.IS_IGNORE_CELL_BORDER,
// Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.OU TPUT_STREAM,
resp.getOutputStream());
exporterXLS.exportReport();
}
*/
context.getApplication().getStateManager().saveVie w(context);
context.responseComplete();
return true;
} catch (Exception e) {
// log.error(e);
System.out.println(e);
} finally {
try {
c.close();
} catch (Exception e1) {
System.out.println(e1);
}
}
return false;
}
Cuando lo ejecuto no me sale error; pero me muestra simbolos nada mas asi:
0000000000 65535 f 0000000919 00000 n 0000001188 00000 n 0000000015 00000 n 0000001276 00000 n 0000001153 00000 n 0000001339 00000 n 0000001393 00000 n 0000001425 00000 n 0000001528 00000 n trailer <<7172286fd6946bdee186ab011a5316c2
y no muestr el pdf.
Que puede ser? agradecer me apoyen en esto.
Gracias