你好,看到你提问iReport在Jsp中不显示pdf,我也遇到同样问题,请您说说怎么解决的啊
2个回答
展开全部
<%
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,访问就是了,注意改下里面对应的参数
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,访问就是了,注意改下里面对应的参数
来自:求助得到的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询