<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="net.sf.jasperreports.engine.JasperFillManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperPrint"%>
<%@ page import="net.sf.jasperreports.engine.JRException"%>
<%@ page import="zte.SQLConn"%>ger"%>
<%@ page import="net.sf.jasperreports.engine.*" %>
<%
System.out.println("----001.success jspreport");
System.out.println("----001.success jspreport");
System.out.println("----001.success jspreport");
//String Name = "1";
SQLConn sqlConn = new SQLConn();
try {
Connection conn= sqlConn.getConnection();
File exe_rpt = new File(application.getRealPath("jspreport/test.jasper"));
Map parameters = new HashMap();
// parameters.put("Name", Name);
if(exe_rpt.exists()){
System.out.println("yes,file");
}else{
System.out.println("no,file");
}
System.out.println("----002.success jspreport");
System.out.println("----002.success jspreport");
System.out.println("----002.success jspreport");
System.out.println(exe_rpt.getPath());
try {
JasperPrint jasperPrint = JasperFillManager.fillReport(new FileInputStream(exe_rpt),parameters,conn);
JasperPrintManager.printReport(jasperPrint, false);
response.setContentType("application/msword");
conn.close();
// JasperPrint jasperPrint = JasperFillManager.fillReport(exe_rpt.getPath(),parameters,conn);
//byte[] bytes = JasperRunManager.runReportToPdf(exe_rpt.getPath(),parameters,conn);
// response.setContentType("application/pdf");
//response.setContentLength(bytes.length);
//ServletOutputStream ouputStream = response.getOutputStream();
//ouputStream.write(bytes,0,bytes.length);
//释放在jsp中使用的对象,会调用response.getWriter(),因为这个方法是和response.getOutputStream()相冲突的!
//使用完输出流以后
out.clear();
out = pageContext.pushBody();
// ouputStream.flush();
// ouputStream.close();
conn.close();
}catch(JRException ex){
out.print("Jasper Output Error:"+ex.getMessage());
}
} catch (SQLException e1) {
e1.printStackTrace();
}
%>
-------------------------调用javaBean做数据源
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="java.sql.*"%>
<%@page import="net.sf.jasperreports.engine.JasperFillManager"%>
<%@page import="net.sf.jasperreports.engine.*"%>
<%@page import="net.sf.jasperreports.engine.util.*"%>
<%@page import="net.sf.jasperreports.engine.export.*"%>
<%@page import="net.sf.jasperreports.j2ee.servlets.*"%>
<%@page import="java.util.*"%>
<%@page import="java.util.List"%>
<%@page import="java.io.*"%>
<%@page import="net.sf.jasperreports.engine.JasperPrintManager"%>
<%@page import="net.sf.jasperreports.view.*"%>
<%@page import="java.sql.*, javax.sql.DataSource, javax.naming.InitialContext"%>
<%@page import="java.lang.*"%>
<%@ page import="net.sf.jasperreports.engine.JasperFillManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperPrint"%>
<%@ page import="net.sf.jasperreports.engine.JasperRunManager"%>
<%@ page import="net.sf.jasperreports.engine.JRExporterParameter"%>
<%@ page import="net.sf.jasperreports.engine.JRException"%>
<%@ page import="net.sf.jasperreports.engine.export.JRXlsExporterParameter"%>
<%@ page import="net.sf.jasperreports.engine.export.JRXlsExporter"%>
<%@page import ="net.sf.jasperreports.engine.JRExporter"%>
<%@ page import="net.sf.jasperreports.engine.export.JRRtfExporter"%>
<%@page import ="com.lowagie.text.*" %>
<%@ page import="zte.SQLConn"%><%@ page import="zte.testVo"%>
<%@ page import="net.sf.jasperreports.engine.JasperRunManager"%>
<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"%>
<%
// InitialContext ctx = new InitialContext();
// DataSource ds = (DataSource) ctx.lookup("java:/MSSQLDS");
// Connection conn = ds.getConnection();
SQLConn sqlConn = new SQLConn();
try {
Connection conn= sqlConn.getConnection1();
//String accNo ="200672395001";
//String accNo = request.getParameter("accNo");
File reportFile1 = new File(application.getRealPath("jspreport/javaBean.jasper"));
if (!reportFile1.exists())
throw new JRRuntimeException("Fidsfsfd. The report design must be compiled first");
JasperReport jasperReport1 = (JasperReport) JRLoader.loadObject(reportFile1.getPath());
Map parameters = new HashMap();
parameters.put("id", 1);
///`--------------------
List<testVo> data = new ArrayList<testVo>();
testVo TestVo = new testVo();
// TestVo.setId1(100);
// TestVo.setName1("肥肥");
// TestVo.setSex1("10");
// TestVo.setAge1("202");
List<testVo> list = new ArrayList<testVo>();
try {
Statement stmt = conn.createStatement();
ResultSet rslt = stmt.executeQuery("select * from PARTNER where partner_id = (select distinct d.supplier_id from PROCUREMENT_ITEM a ,BIDDING b ,AUCTION c,MATERIAL_PRICE d where a.procurement_item_id = b.procurement_item_id and b.bidding_id =c.bidding_id and c.auction_id = d.auction_id)");
while (rslt.next()) {
testVo obj = new testVo();
obj.setContactMan(rslt.getString("CONTACT_MAN"));
obj.setContactTel(rslt.getString("contact_Tel"));
obj.setBank(rslt.getString("bank"));
obj.setAccount(rslt.getString("account"));
list.add(obj);
}
for(int i=0;i<list.size();i++){
TestVo.setContactMan(list.get(i).getContactMan());
TestVo.setContactTel(list.get(i).getContactTel());
TestVo.setBank(list.get(i).getBank());
TestVo.setAccount(list.get(i).getAccount());
}
} catch (SQLException e) {
e.printStackTrace();
}
data.add(TestVo);
JRDataSource dataSource = new JRBeanCollectionDataSource(data);
//--------------
JasperPrint jasperPrint1 =
JasperFillManager.fillReport(
jasperReport1,
null,
dataSource
);
//response.setContentType("application/ms_word");
JRExporter exporter = null;
exporter = new JRRtfExporter();
List reportlist = (List)new java.util.ArrayList();
reportlist.add(jasperPrint1);
// System.out.println(reportlist.size() + "list");
byte[] bytes;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, reportlist);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
//qijia
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint1);
//exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
exporter.exportReport();
// exporter.exportReportToStream();
bytes = baos.toByteArray();
// System.out.println(bytes+"bytes");
if (bytes != null && bytes.length > 0) {
try {
//response.reset();
response.setContentType("application/ms_word");
response.setHeader("Content-disposition",
"attachment; filename=yourReport.doc");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
//ouputStream.flush();
out.clear();
out = pageContext.pushBody();
ouputStream.close();
// response.reset();
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
conn.close();
}
}
} catch (SQLException e1) {
e1.printStackTrace();
}
%>
------------------------connction做数据源
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="java.sql.*"%>
<%@page import="net.sf.jasperreports.engine.JasperFillManager"%>
<%@page import="net.sf.jasperreports.engine.*"%>
<%@page import="net.sf.jasperreports.engine.util.*"%>
<%@page import="net.sf.jasperreports.engine.export.*"%>
<%@page import="net.sf.jasperreports.j2ee.servlets.*"%>
<%@page import="java.util.*"%>
<%@page import="java.util.List"%>
<%@page import="java.io.*"%>
<%@page import="net.sf.jasperreports.engine.JasperPrintManager"%>
<%@page import="net.sf.jasperreports.view.*"%>
<%@page import="java.sql.*, javax.sql.DataSource, javax.naming.InitialContext"%>
<%@page import="java.lang.*"%>
<%@ page import="net.sf.jasperreports.engine.JasperPrint"%>
<%@ page import="net.sf.jasperreports.engine.JRExporterParameter"%>
<%@page import ="net.sf.jasperreports.engine.JRExporter"%>
<%@ page import="net.sf.jasperreports.engine.export.JRRtfExporter"%>
<%@page import ="com.lowagie.text.*" %>
<%@ page import="zte.SQLConn"%><%@ page import="zte.testVo"%>
<%@ page import="net.sf.jasperreports.engine.JasperRunManager"%>
<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"%>
<%
// InitialContext ctx = new InitialContext();
// DataSource ds = (DataSource) ctx.lookup("java:/MSSQLDS");
// Connection conn = ds.getConnection();
SQLConn sqlConn = new SQLConn();
try {
Connection conn= sqlConn.getConnection();
//String accNo ="200672395001";
//String accNo = request.getParameter("accNo");
File reportFile1 = new File(application.getRealPath("jspreport/conntion.jasper"));
if (!reportFile1.exists())
throw new JRRuntimeException("Fidsfsfd. The report design must be compiled first");
JasperReport jasperReport1 = (JasperReport) JRLoader.loadObject(reportFile1.getPath());
Map parameters = new HashMap();
parameters.put("id", 1);
JasperPrint jasperPrint1 =
JasperFillManager.fillReport(
jasperReport1,
parameters,
conn
);
//response.setContentType("application/ms_word");
JRExporter exporter = null;
exporter = new JRRtfExporter();
List reportlist = (List)new java.util.ArrayList();
reportlist.add(jasperPrint1);
// System.out.println(reportlist.size() + "list");
byte[] bytes;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, reportlist);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
//qijia
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint1);
//exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
exporter.exportReport();
// exporter.exportReportToStream();
bytes = baos.toByteArray();
// System.out.println(bytes+"bytes");
if (bytes != null && bytes.length > 0) {
try {
//response.reset();
response.setContentType("application/ms_word");
response.setHeader("Content-disposition",
"attachment; filename=yourReport.doc");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
//ouputStream.flush();
out.clear();
out = pageContext.pushBody();
ouputStream.close();
// response.reset();
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
conn.close();
}
}
} catch (SQLException e1) {
e1.printStackTrace();
}
%>
----------------------包
commons-beanutils-1.7.jar
commons-collections-3.1.jar
iText-2.1.7.jar
iTextAsian.jar
jakarta-bcel-20050813.jar
JasperBabylon-1.0.0.jar
jasperreports-3.0.0.jar
jasperreports-extensions-1.3.1.jar
jasperreports-flash-2.0.5.jar
mysql-connector-java-3.1.11-bin.jar
分享到:
相关推荐
Web应用可以通过Servlet或JSP调用JasperReport API来生成报表,并将其嵌入到网页中。用户可以通过参数传递定制报表,例如筛选条件、日期范围等。 10. **最佳实践** - 保持报表设计简洁,避免过多的复杂性。 - ...
Java 实现 iReport 转换为 PDF 是一个常见的任务,尤其在企业级应用中,经常需要将报表数据...但总的来说,Java 结合 iReport 和 JasperReports 提供了一种灵活且功能强大的方式来生成 PDF 报表,满足各种业务需求。
Java JSP调用iReport动态模板打印是一种在Web应用程序中实现报表打印的常见技术。iReport是一款开源的报表设计工具,它可以与Java、JSP、Servlets等进行集成,为开发者提供灵活的报表生成和打印功能。在这个场景下,...
在这个案例中,视图可能是一个JSP页面,该页面将调用iReport生成的二维码图像。 接下来,我们探讨iReport的使用。iReport允许用户通过直观的图形界面设计报表模板。对于二维码的生成,我们可能需要创建一个包含...
本项目是基于JSP(JavaServer Pages)技术结合iReport工具实现的一个分页报表程序,旨在提供高效、易用的数据可视化解决方案。 JSP是一种动态网页开发技术,它允许开发者在HTML或者XML文档中嵌入Java代码,从而实现...
以下是一个简单的JSP示例,展示了如何在web应用中调用ireport设计的报表: ```jsp ;charset=GB2312"%> <!-- 其他import语句省略 --> String rptpath = application.getRealPath("/report/jasper"); String ...
标题中的“ireport+jsp基于jasperReport 实现导出报表至web页面”是指使用iReport工具和JasperReport库,结合JavaServer Pages (JSP) 技术,来创建和展示动态报表,并能将这些报表导出到Web页面上供用户查看。...
3. **调用jasper文件的页面**:这部分通常是指一个JSP页面(如示例中的`reports.jsp`),它的主要职责是从查询页面收集参数,并调用.jasper文件来生成最终的报表。 #### reports.jsp的作用及实现方式 - **动态接收...
总的来说,JasperReports和iReport的组合为开发者提供了一套强大的报表解决方案,不仅可以用于单一报表的生成,还支持大规模的数据处理和批量打印。通过学习和实践,开发者能够灵活地满足各种复杂的打印需求。
总结来说,这个项目展示了如何在JavaWeb环境下利用Ireport和JasperReports创建报表,同时结合JavaBean处理业务逻辑,并通过Mysql数据库获取数据。对于想要学习JavaWeb报表开发或者希望增强现有应用报表功能的开发者...
它基于JasperReports库,能够与各种数据库配合,生成PDF、HTML、Excel等多种格式的报表。本文将详细介绍在Windows环境下使用iReport制作报表的全过程,以及如何在Web和胖客户端应用中集成Jasperreport报表控件。 **...
6. **JasperReports结合iReport制作报表教程.pdf** - 一个详细的教程,讲述了如何结合iReport和JasperReports来创建和管理报表。 7. **JasperReport核心API.pdf** - 关于JasperReport的核心API的详细文档,是开发...
将Struts2与JasperReports结合使用,可以方便地在Web应用中实现动态报表的生成和展示。 首先,我们需要了解Struts2中整合JasperReports的基本步骤: 1. **环境准备**:确保你已经安装了MyEclipse开发环境,并且在...
JasperReport是一个开源的报表生成库,它可以读取由iReport设计的模板,结合业务数据生成各种格式的报表,如PDF、HTML、Excel等。JasperReport的强大在于它的灵活性,可以处理动态数据,支持数据分组、排序、过滤等...
总的来说,在JSP中导出PDF和Excel文档,需要理解JasperReports的工作原理,掌握报表设计工具iReport的使用,以及熟悉相关库的配置和调用。通过这些工具和库,开发者能够轻松地将Web应用中的数据以美观的格式呈现给...
JasperReport不仅可以在iReport中设计报表,还可以直接在JSP、Servlet等程序中调用,实现动态报表生成。此外,文章还介绍了动态SQL的应用、条件打印、PDF直接打印等功能,以及常见错误的处理方法。 #### 结论 ...
1. JSP嵌入:将生成的报表(.jasper)文件嵌入到JSP页面中,通过Servlet如JasperViewerServlet来呈现报表。 2. REST API:iReport可以通过RESTful服务提供报表,与前端JavaScript框架如AngularJS、React等进行交互。 3...
通常,报表的生成会涉及到JasperReport库,使用`JasperFillManager.fillReport()`方法填充报表,然后通过`JasperExportManager.exportReportToXXX()`方法导出为PDF、Excel或Word格式。 4. **页面显示**:在Struts的...
在IT行业中,报表生成是企业应用中不可或缺的一部分,而`iReport`则是一款强大的报表设计工具,它与MyEclipse、Struts2等框架结合,能够帮助开发者轻松创建复杂的业务报表。本文将深入探讨`iReport`在Java开发中的...