问题描述
- ireport,在java工程中预览PDF,被识别为文件下载
-
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(host,
user, pass);
Map parameters = new HashMap();
parameters.put("SUBREPORT_DIR", reportFilePath);
if (para != null && !para.equals("0")) {
parameters.put("Id", para);
}
if (organizationType != null && !organizationType.equals("")) {
parameters.put("organizationType", organizationType);
}
if (organizationName != null && !organizationName.equals("")) {
parameters.put("organizationName", organizationName);
}
if (!workerType.equals(""))
{
workerType= new String(workerType.getBytes("ISO8859_1"), "utf-8");
parameters.put("workerType", workerType);
}byte[] bytes = JasperRunManager.runReportToPdf( reportFile.getPath(), parameters, conn); response.setContentType("application/pdf"); response.setContentLength(bytes.length); ServletOutputStream outputStream = response.getOutputStream(); out.clear(); out = pageContext.pushBody(); outputStream.write(bytes, 0, bytes.length); outputStream.flush(); outputStream .close(); JasperPrint print = JasperFillManager.fillReport( reportFile.getPath(), parameters, conn); JasperPrintManager.printReport(print, true); conn.close();
这是生成PDF预览的代码, 在我自己机子上是正常预览PDF,而别人的机子是变成一个文件下载。。。是不是因为浏览器插件问题呢,还是代码有问题,,请大神指教
时间: 2024-10-30 11:39:57