我用ireport设计好报表了,怎么将.jrxml的文件编译成.jasper的呢?

加减算法 2004-07-28 11:53:44
用ireport编译之后产生一个.java文件,不知这个有什么用?
我想在jsp页面中调用报表,怎么做?
如有资料发给我最好:jdh1@21cn.com,万分感谢
...全文
7627 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyatwh 2005-04-21
  • 打赏
  • 举报
回复
在编译时iReport就会自动生成.jasper文件,只不过你没设置存放路径。在tools中选Options... ,
Compiler选择你要存放路径并勾上另两个选项。
你再次编译后,就会在你选中的目录中看到了。
kaizaixian 2004-11-01
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="net.sf.jasperreports.engine.*" %>
<%

try
{System.setProperty(
"jasper.reports.compile.class.path",
application.getRealPath("/WEB-INF/lib/jasperreports-0.6.1.jar") +
System.getProperty("path.separator") +
application.getRealPath("/WEB-INF/classes/")
);

System.setProperty(
"jasper.reports.compile.temp",
application.getRealPath("/reports/")
);

JasperCompileManager.compileReportToFile(application.getRealPath("/reports/kai.jrxml"));
}catch(Exception e){
out.print("有错误");
out.print("e="+e);
out.print(" e.toString="+e.toString());

}
%>
<html>
<head>
<title>
CompilePage
</title>
</head>
<body bgcolor="#ffffff">
<h1><font color="blue">Compile is ok!!</font>
</h1>
<form method="post" action="ViewReport.jsp">
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
bibiye 2004-08-05
  • 打赏
  • 举报
回复
JasperReports安装配置和制作
一、JasperReports简要介绍
^JasperReports is a powerful open source Java reporting tool that has the ability to deliver rich content onto the screen, to the printer or into PDF, HTML, XLS, CSV and XML files.

It is entirely written in Java and can be used in a variety of Java enabled applications, including J2EE or Web applications, to generate dynamic content.

Its main purpose is to help creating page oriented, ready to print documents in a simple and flexible manner.

二、以下为JasperReports安装配置和制作步骤,希望能对初学者有所帮助。

1、JasperReport和iReport的资源,最新版本可以到下面官方网站得到。

iReport官方网站:
http://ireport.sourceforge.net

JasperReports官方网站:
http://jasperreports.sourceforge.net

2、安装
1)、JDK的安装,并配置JAVA_HOME。比如我的JAVA_HOME路径如下:
JAVA_HOME  D:\Program Files\j2sdk1.4.2_03

2)、由于中文的问题,所以还需要下载:itext-1.02b.jar和iTextAsian.jar包。下载地址:http://itext.sourceforge.net/downloads/iTextAsian.jar
并在CLASSPATH中设置。例如我的CLASSPATH如下:
CLASSPATH E:\Program Files\Apache Group\Tomcat4.1\webapps\testreport\WEB-INF\lib\itext-1.02b.jar;E:\Program Files\Apache Group\Tomcat 4.1\webapps\testreport\WEB-INF\lib\iTextAsian.jar;E:\Program Files\Apache Group\Tomcat 4.1\webapps\testreport\WEB-INF\lib;D:\tools\iReport0.2.3\lib

3)、iReport的安装iReport只要解压就OK,如果没有安装Ant,可以直接在iReport下的noAnt目录下,
运行startup.bat就可以了,这样iReport就可以启动了。

4)、JasperReport
Jasperreport不需要任何配置,你只需将下载以后的jar包放到classpath下即可。

5)、数据库的JDBC驱动包
加入到CLASSPATH中

3、详细资源
iReport官方提供了一些关于iReport视频,对于初学者很有帮助:
地址:http://ireport.sourceforge.net/docs.html

JasperReport官方提供的使用指南
地址:http://jasperreports.sourceforge.net/tutorial/index.html

JasperReport提供的一些例子:
地址:http://jasperreports.sourceforge.net/samples/index.html

4、常见问题
1)、iReport中提示框输入中文是不能正常显示,请将iReport下lib中的这个包删除tinylaf.jar
2)、在iReport中运行报表时如果出现乱码问题,请检查itext-1.02b.jar和iTextAsian.jar这两个包是否加到CLASSPATH
3)、在jsp或servlet高度报表时出现乱码或不显示,请检查你在报表设计过程中所设置的字体及其编码。比如:pdfname、pdfencoding

5 、 下面是两个调试例子    
Servlet :
import javax.servlet.*;
import javax.servlet.http.*;
import dori.jasper.engine.*;
import java.io.*;
import java.util.*;
import java.sql.*;

/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class TestReport extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection conn = null;

try {

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn =
DriverManager.getConnection(
"jdbc:microsoft:sqlserver://192.168.0.10:1433;DatabaseName=pm;user=sa;password=sa");

ServletContext servletContext = this.getServletContext();
File reportFile =
new File(servletContext.getRealPath("test/iteminfo.jasper"));
Map parameters = new HashMap();
Integer i = new Integer(8);
parameters.put("pjId", i);
byte[] bytes =
JasperRunManager.runReportToPdf(
reportFile.getPath(),
parameters,
conn);
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
} catch (JRException jre) {
System.out.println("JRException:" + jre.getMessage());
} catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}

}

public void doPost(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

doGet(request, response);

}

}

JSP:
< %@ page contentType="text/html;charset=GBK" % >
< %@ page import="dori.jasper.engine.*" % >
< %@ page import="java.util.*" % >
< %@ page import="java.io.*" % >
< %@ page import="java.sql.*" % >

< %
//数据库连接
Connection conn=null;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.10:1433;DatabaseName=pm;user=sa;password=sa");

//取到编译后的jasper文件
File reportFile = new File(application.getRealPath("test/iteminfo.jasper"));

//向报表中定义的参数赋值
Map parameters = new HashMap();
Integer i=new Integer(8);
parameters.put("pjId", i);

byte[] bytes =
JasperRunManager.runReportToPdf(
reportFile.getPath(),
parameters,
conn
);

response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
% >


yufeng13 2004-08-05
  • 打赏
  • 举报
回复
我也碰到如何在jsp中传参数的问题,怎么解决啊,顶顶顶顶顶顶顶顶顶顶顶顶
谁有jasperreports的详细文档啊。救命啊!!

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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