你好,看到你提问iReport在Jsp中不显示pdf,我也遇到同样问题,请您说说怎么解决的啊

2025-03-28 21:05:26
推荐回答(2个)
回答(1):

<%
String title= "我的保镖";
File reportFile = new File(application.getRealPath("/report/kpmx.jasper"));
String path=application.getRealPath("/report/");
Map parameters = new HashMap();
parameters.put("title", title);
parameters.put("SUBREPORT_DIR", path+"\\");
try {
Connection conn = null;

try{
conn = xxx.getConnection();
}catch (SQLException e) {
e.printStackTrace();
}
byte[] bytes =JasperRunManager.runReportToPdf( reportFile.getPath(), parameters, conn);
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
conn.close();
} catch (JRException jre) {
System.out.println("JRException:" + jre.getMessage());
} catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
%>

上面代码保存成jsp,访问就是了,注意改下里面对应的参数

回答(2):

具体什么错误?