ireport 求高手呀
web 项目 导入的包有 iTextAsian
iText-2.1.7.jar
jasper-4.8.jar
ipeport 已经有查询语句
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.*" %>
<%@ page import="
net.sf.jasperreports.engine.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ include file="/common/taglibs.jsp"%>
<%
File reportFile = new File(this.getServletContext().
getRealPath("/report/jh.jasper"));
String url="jdbc:jtds:sqlserver://192.168.1.15:1433;DatabaseName=anjian;";
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Map parameters = new HashMap();
//"SQLSTR"是报表中定义的一个参数名称,其类型为String 型
// parameters.put("SQLSTR",
// "select * from test_student");
Connection conn = DriverManager.getConnection(url,
"sa", "sa");
//生成pdf文件
byte[] bytes=JasperRunManager.
runReportToPdf(reportFile.getPath(),null,conn);
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream outStream = response.getOutputStream();
outStream.write(bytes,0,bytes.length);
outStream.flush();
outStream.close();
out.clear();
out = pageContext.pushBody();
//生成html
// JasperRunManager.runReportToHtmlFile(reportFile.getPath(),parameters,conn);
// response.sendRedirect(this.getServletContext().
//getRealPath("/report/jh.html"));
%> 纠结了半天了
------解决方案--------------------ServletOutputStream outStream = response.getOutputStream();
outStream.write(bytes,0,bytes.length);
outStream.flush();
outStream.close();
out.clear();
流读写,你就这样写吗?
套用标准的模板。
------解决方案--------------------
查询语句不需要手动带入进去吗?
为什么要注释掉?
//"SQLSTR"是报表中定义的一个参数名称,其类型为String 型
// parameters.put("SQLSTR",
// "select * from test_student");
runReportToPdf(reportFile.getPath(),parameters,conn);