jsp怎么做报表
2个回答
推荐于2016-08-30 · 知道合伙人数码行家
关注
展开全部
先需要做好一张报表的模板,工具最好用iReport, 做好后会生成两种文件。 后缀 .jasper 和 .jrxml 的报表文件。然后把这两个文件 和一个JSP页面放到同一目录下, 在JSP文件里面配置数据源:代码:<%@ page import="com.handson.service.report.*,java.sql.*"%>
<%@ page contentType="text/html;charset=GBK"%>
<jsp:directive.page import="java.util.*" />
<jsp:directive.page import="java.util.HashMap" />
<jsp:directive.page
import="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource" />
<%
Collection coll = (Collection) request.getAttribute("putinReportList"); //putinReportList是由请求传来的LIST
//设置数据库JDBC连接
JRBeanCollectionDataSource con = new JRBeanCollectionDataSource(
coll);
//设置外部参数对
Map parameters = new HashMap();
//parameters.put("rptToday", "2008-01-11");
//parameters.put("rptMan", "sterning"); PDFExport exportReport = new PDFExport();
exportReport.exportToPDF(request, response, out, request
.getRealPath("/reports/putin_report.jrxml"), request
.getRealPath("/reports/putin_report.jasper"), parameters,
con);
out.clear();
out=pageContext.pushBody();
%>
<%@ page contentType="text/html;charset=GBK"%>
<jsp:directive.page import="java.util.*" />
<jsp:directive.page import="java.util.HashMap" />
<jsp:directive.page
import="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource" />
<%
Collection coll = (Collection) request.getAttribute("putinReportList"); //putinReportList是由请求传来的LIST
//设置数据库JDBC连接
JRBeanCollectionDataSource con = new JRBeanCollectionDataSource(
coll);
//设置外部参数对
Map parameters = new HashMap();
//parameters.put("rptToday", "2008-01-11");
//parameters.put("rptMan", "sterning"); PDFExport exportReport = new PDFExport();
exportReport.exportToPDF(request, response, out, request
.getRealPath("/reports/putin_report.jrxml"), request
.getRealPath("/reports/putin_report.jasper"), parameters,
con);
out.clear();
out=pageContext.pushBody();
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询