jasperreport生成报表的值为null

tondayong1981 2006-05-21 08:01:44
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>TestReport</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 36px}
.style7 {color: #FF0000}
-->
</style>
</head>
<body>
<%@ page import="net.sf.jasperreports.engine.*"%>
<%@ page import="net.sf.jasperreports.engine.util.*"%>
<%@ page import="net.sf.jasperreports.engine.export.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%
final String DATABASE_URL ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=DataOperationPlatform";
final String DATABASE_USER ="sa";
final String DATABASE_PASSWORD ="";
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
String fileName="";

try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

}catch(ClassNotFoundException e)
{
out.println(e.getMessage());
}
try
{
conn=DriverManager.getConnection(DATABASE_URL,DATABASE_USER,DATABASE_PASSWORD);

File reportFile = new File(application.getRealPath("FirstReport.jasper"));
Map parameters = new HashMap();
//parameters.put("filename","111");

byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters,new JREmptyDataSource());
response.setContentType("application/pdf");

response.setContentLength(bytes.length);
FileOutputStream fos=new FileOutputStream("c:\\MyReport.pdf");
fos.write(bytes);
fos.close();


}
catch (SQLException ex)
{
ex.printStackTrace();
}
catch (JRException e)
{
e.printStackTrace();
}
%>
</body>
</html>
大家帮我看看为什么生成报表的值都为null.调试了一天了.
...全文
371 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
TONYBLARED 2006-05-25
  • 打赏
  • 举报
回复
Mark.I am doing some job about JasperReport.
szawei9196 2006-05-25
  • 打赏
  • 举报
回复
改一下直接输出到浏览器吧,把
FileOutputStream fos=new FileOutputStream("c:\\MyReport.pdf");
fos.write(bytes);
fos.close();
改成
ServletOutputStream outputStream=response.getOutputStream();
outputStream.write(bytes,0,bytes.length);
outputStream.fluse();
outputStream.close();
最好下个IREPORT,这样方便调试!
tondayong1981 2006-05-25
  • 打赏
  • 举报
回复
我改了之后,程序根本就不能执行到最后啊,
byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters,conn);执行到这一句就不往下执行了,不止为什么??
szawei9196 2006-05-25
  • 打赏
  • 举报
回复
byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters,new JREmptyDataSource());
new JREmptyDataSource()应该改为你已经获得的连接conn吧!
tondayong1981 2006-05-23
  • 打赏
  • 举报
回复
怎么没人回我啊
tondayong1981 2006-05-22
  • 打赏
  • 举报
回复
没有啊,我设置了啊
babytomato 2006-05-22
  • 打赏
  • 举报
回复
是不是没有动态连接?

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧