ireport,在java工程中预览PDF,被识别为文件下载
Class.forName(driver).newInstance();Connectionconn=DriverManager.getConnection(host,u...
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,而别人的机子是变成一个文件下载。。。是不是因为浏览器插件问题呢,还是代码有问题,,请大神指教 展开
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,而别人的机子是变成一个文件下载。。。是不是因为浏览器插件问题呢,还是代码有问题,,请大神指教 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询