iReport和JasperReport的问题

竭力进到完全的地步 2004-10-01 10:12:34
我在JSP中生成动态的pdf格式的报表:
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ page import="dori.jasper.engine.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.servlet.*" %>
<html>
<head>
<title></title>
<link href="../common/css/newmoon.css" rel="stylesheet" type="text/css">
<body leftmargin="0" topmargin="0">
<!--img border="0" width="50" height="50" src="../servlet/generateReport" -->
<%
try {
Map parameters = new HashMap();
parameters.put("name", "w");
Connection connection = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url =
"jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb);DBQ=H:/wanghua/WebReport/tree.mdb";
connection = DriverManager.getConnection(url, "", "");
byte[] bytes =
JasperRunManager.runReportToPdf(
request.getRealPath("/report/jasper/myWebReport.jasper"),
parameters,
connection
);
System.out.println("=============2=============");
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 ex) {
ex.printStackTrace();
}
%>
</body>
</html>
运行时报异常:
StandardWrapperValve[debugjsp]: Servlet.service() for servlet debugjsp threw exception
javax.servlet.ServletException: com/lowagie/text/DocumentException
javax.servlet.ServletException: com/lowagie/text/DocumentException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471)
at org.apache.jsp.pdf$jsp._jspService(pdf$jsp.java:135)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
我的jrxml文件如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
name="myWebReport"
columnCount="1"
printOrder="Vertical"
orientation="Portrait"
pageWidth="595"
pageHeight="842"
columnWidth="535"
columnSpacing="0"
leftMargin="30"
rightMargin="30"
topMargin="20"
bottomMargin="20"
whenNoDataType="NoPages"
isTitleNewPage="false"
isSummaryNewPage="false">
<property name="ireport.scriptlethandling" value="2" />
<reportFont name="songti" isDefault="false" fontName="宋体" size="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
<queryString><![CDATA[select * from student where name like '%$P{name}%']]></queryString>
<field name="编号" class="java.lang.Integer"/>
<field name="id" class="java.lang.Integer"/>
<field name="name" class="java.lang.String"/>
<field name="gender" class="java.lang.String"/>
<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="50" isSplitAllowed="true" >
</band>
</title>
<pageHeader>
<band height="50" isSplitAllowed="true" >
</band>
</pageHeader>
<columnHeader>
<band height="30" isSplitAllowed="true" >
<staticText>
<reportElement
mode="Opaque"
x="154"
y="6"
width="53"
height="16"
forecolor="#000000"
backcolor="#FFFFFF"
key="staticText-1"
stretchType="NoStretch"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">
<font reportFont="songti" isPdfEmbedded ="false"/>
</textElement>
<text><![CDATA[姓名]]></text>
</staticText>
<staticText>
<reportElement
mode="Opaque"
x="269"
y="7"
width="45"
height="15"
forecolor="#000000"
backcolor="#FFFFFF"
key="staticText-2"
stretchType="NoStretch"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">
<font reportFont="songti" isPdfEmbedded ="false"/>
</textElement>
<text><![CDATA[性别]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="100" isSplitAllowed="true" >
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement
mode="Opaque"
x="154"
y="8"
width="88"
height="20"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-3"
stretchType="NoStretch"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">
<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement
mode="Opaque"
x="269"
y="8"
width="84"
height="20"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-4"
stretchType="NoStretch"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">
<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{gender}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="30" isSplitAllowed="true" >
</band>
</columnFooter>
<pageFooter>
<band height="50" isSplitAllowed="true" >
</band>
</pageFooter>
<summary>
<band height="50" isSplitAllowed="true" >
</band>
</summary>
</jasperReport>
我把jasper文件和jrxml文件都放在Tomcat的webapp目录下面的\report\jasper目录中了。
这个问题如何解决?
...全文
90 点赞 收藏 回复
写回复
回复
切换为时间正序
请发表友善的回复…
发表回复

还没有回复,快来抢沙发~

发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告