请教高人:再论报表的显示问题

05-04-25 ronghao100

目前我正在用jasperreport+ireport做报表,现在已经能够产生.xls,.html,.csv,.pdf文件
问题:如何在当前浏览页中显示这些文件?代码如下:
File reportFile = new File(application.getRealPath("/report/test.jasper"));
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());
Map parameters = new HashMap();
parameters.put("pname", "rong");
Connection conn=null;

//数据库连接过程

Mysql mysql=new Mysql();
conn=mysql.getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,conn);
JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
exporter.exportReport();

用上面的代码显示不正常,请问问题在什么地方??谢谢!!



<%File reportFile = new File(application.getRealPath("/report/test.jasper")); 
        JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath()); 
	Map parameters = new HashMap();
	parameters.put("pname", "rong");
	Connection conn=null;
	
	//数据库连接过程

	Mysql mysql=new Mysql();
	conn=mysql.getConnection();
	JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,conn); 
         JRHtmlExporter exporter = new JRHtmlExporter();
         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
        exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
        exporter.exportReport(); 
%>[/

ronghao100
2005-04-25 14:26

显示PDF的代码同样显示不正常。代码如下:
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();

ronghao100
2005-04-29 14:21

数据库中是中文,ireport在从数据库中读取字段时是乱码,有没有人教我一下,谢谢!

ronghao100
2005-04-29 14:23

还有,如何在IREPORT中进行加法、乘法的运算??谢谢!

ronghao100
2005-04-29 16:17

搞定!
看样子简单的问题都没人理啊:)