使用Jasperreport作为报表控件开发Web 报表应用 后续

来源:互联网 发布:软件 风险矩阵表 编辑:程序博客网 时间:2024/06/11 21:02

参考如下:  
  <%@page   contentType="text/html;charset=gbk"%>  
  <%@   page   import="net.sf.jasperreports.engine.*"   %>  
  <%@   page   import="net.sf.jasperreports.engine.util.*"   %>  
  <%@   page   import="net.sf.jasperreports.engine.export.*"   %>  
  <%@   page   import="java.util.*,java.io.*,java.sql.*"   %>  
   
   
  <%  
  String   jasperFileName   =   "emp"   ;  
  File   jasperFile   =   new   File(application.getRealPath("//report//emp.jasper"));  
   
  Map   parameters   =   new   HashMap();  
  System.out.println("::::::::::::::::DS   OK1:"+jasperFile.getPath());  
  parameters.put("dd","LYD1");  
   
  Connection   con   =   null;  
  try{  
  Class.forName("com.mysql.jdbc.Driver").newInstance();  
  con   =   DriverManager.getConnection("jdbc:mysql://localhost:3306/photo","root","root");  
  }catch(Exception   e){  
  System.out.println("::::::::::::::::DS   fail");  
  }  
   
              JasperReport   jasperReport   =   (JasperReport)   JRLoader.loadObject(jasperFile.getPath());  
   
              JasperPrint   jasperPrint   =  
                      JasperFillManager.fillReport(  
                      jasperReport,  
                      parameters,  
                      con  
                      );  
                       
  JRHtmlExporter   exporter   =   new   JRHtmlExporter();  
   
  //exporter.setParameter(JRExporterParameter.JASPER_PRINT,   jasperPrint);  
  //exporter.setParameter(JRExporterParameter.OUTPUT_WRITER,   out);  
  Map   imagesMap   =   new   HashMap();  
  session.setAttribute("IMAGES_MAP",   imagesMap);  
   
  exporter.setParameter(JRExporterParameter.JASPER_PRINT,   jasperPrint);  
  exporter.setParameter(JRExporterParameter.OUTPUT_WRITER,   out);  
  exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP,   imagesMap);  
  exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,   "image.jsp?image=");  
   
  exporter.exportReport();  
   
  %>   


 JasperFillManager类 fillreport 方法

fillReport

public static JasperPrint fillReport(java.io.InputStream inputStream,                                     java.util.Map parameters,                                     java.sql.Connection connection)                              throws JRException
Fills the compiled report design loaded from the supplied input stream and returns the generated report object.

 

Parameters:
inputStream - input stream to read the compiled report design object from
parameters - report parameters map
connection - JDBC connection object to use for executing the report internal SQL query
Returns:
generated report object
Throws:
JRException

fillReport

public static JasperPrint fillReport(java.io.InputStream inputStream,                                     java.util.Map parameters)                              throws JRException
Fills the compiled report design loaded from the supplied input stream and returns the generated report object.

 

Parameters:
inputStream - input stream to read the compiled report design object from
parameters - report parameters map
Returns:
generated report object
Throws:
JRException
See Also:
JRFiller.fillReport(JasperReport, Map)

fillReport

public static JasperPrint fillReport(JasperReport jasperReport,                                     java.util.Map parameters,                                     java.sql.Connection connection)                              throws JRException
Fills the compiled report design supplied as the first parameter and returns the generated report object.

 

Parameters:
jasperReport - compiled report design object to use for filling
parameters - report parameters map
connection - JDBC connection object to use for executing the report internal SQL query
Returns:
generated report object
Throws:
JRException

fillReport

public static JasperPrint fillReport(JasperReport jasperReport,                                     java.util.Map parameters)                              throws JRException
Fills the compiled report design supplied as the first parameter and returns the generated report object.

 

Parameters:
jasperReport - compiled report design object to use for filling
parameters - report parameters map
Returns:
generated report object
Throws:
JRException
See Also:
JRFiller.fillReport(JasperReport, Map)