Calling the Ireport report file in JSP and displaying the effect source code
<% @ Page language = "java" contentType = "text/html; charset = UTF-8"
PageEncoding = "UTF-8" %>
<% @ Page
Import = "java. io .*,
Net. sf. jasperreports. engine .*,
Net. sf. jasperreports. engine. util .*,
Java. util. *, java. SQL .*,
Net. sf. jasperreports. engine. export. * "%>
Insert title here
<%
// Obtain parameters
String deptId = (String) request. getParameter ("deptId ");
String xmlxdm = (String) request. getParameter ("xmlxdm ");
String planYear = (String) request. getParameter ("planYear ");
// Call the Report Template
File reportFile = new File (application. getRealPath ("/report/RoadPlanExportExcel. jasper "));
JasperReport jasperReport = (JasperReport) JRLoader. loadObject (reportFile. getPath ());
// Pass parameters to the report
Map Parameters = new HashMap ();
Parameters. put ("deptId", deptId );
Parameters. put ("xmlxdm", xmlxdm );
Parameters. put ("planYear", planYear );
Parameters. put ("title", planYear + "XXXXXX project table --");
// Connect to the data source through JDBC
Connection conn = null;
Try {
Class. forName ("oracle. jdbc. driver. OracleDriver ");
Conn = DriverManager. getConnection (
"Jdbc: oracle: thin: @ 127.0.0.1: 1521: XXX", "XXXX", "XXXX ");
JasperPrint jasperPrint = JasperFillManager. fillReport (
JasperReport, parameters, conn );
JRHtmlExporter exporter = new JRHtmlExporter ();
Exporter. setParameter (JRExporterParameter. JASPER_PRINT, jasperPrint );
Exporter. setParameter (JRExporterParameter. OUTPUT_WRITER, out );
Exporter. setParameter (JRHtmlExporterParameter. IS_USING_IMAGES_TO_ALIGN, Boolean. FALSE );
Exporter. exportReport ();
Out. flush ();
Conn. close ();
} Catch (Exception e ){
If (null! = Conn) conn. close ();
E. printStackTrace ();
} Finally {
If (null! = Conn) conn. close ();
}
%>