public void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
try{
Connection con=ConnectionManager.getConnection();
String root_path="D:/study tools/admin.jrxml";
JasperReport report = (JasperReport) JRLoader.loadObject(root_path);
JasperPrint jasperPrint = JasperFillManager.fillReport(report, new HashMap(),con);
resp.setContentType("application/pdf");
resp.setCharacterEncoding("UTF-8");
resp.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode("PDF报表", "UTF-8")+ ".pdf\"");
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
//exporter.setParameters(parameters);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, resp.getOutputStream());
exporter.exportReport();
}catch(Exception e){
e.printStackTrace();
}
}
我是通过一个页面提交到这个Servlet中,想显示报表,帮忙看一下有什么错误,运行时报错
try{
Connection con=ConnectionManager.getConnection();
String root_path="D:/study tools/admin.jrxml";
JasperReport report = (JasperReport) JRLoader.loadObject(root_path);
JasperPrint jasperPrint = JasperFillManager.fillReport(report, new HashMap(),con);
resp.setContentType("application/pdf");
resp.setCharacterEncoding("UTF-8");
resp.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode("PDF报表", "UTF-8")+ ".pdf\"");
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
//exporter.setParameters(parameters);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, resp.getOutputStream());
exporter.exportReport();
}catch(Exception e){
e.printStackTrace();
}
}
我是通过一个页面提交到这个Servlet中,想显示报表,帮忙看一下有什么错误,运行时报错
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货