Servlets 从servlet调用jasper报表时出错

Servlets 从servlet调用jasper报表时出错,servlets,jasper-reports,subreport,Servlets,Jasper Reports,Subreport,我不熟悉报告的概念,从servlet调用报告时遇到问题。我创建了一份显示学生成绩的报告和一份显示每个学生平均成绩的子报告。我的报告代码为: <?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 6.1.1.final using JasperReports Library version 6.1.1 --> <!-- 2015-10-30T20:0

我不熟悉报告的概念,从servlet调用报告时遇到问题。我创建了一份显示学生成绩的报告和一份显示每个学生平均成绩的子报告。我的报告代码为:

<?xml version="1.0" encoding="UTF-8"?>
 <!-- Created with Jaspersoft Studio version 6.1.1.final using JasperReports Library version 6.1.1  -->
  <!-- 2015-10-30T20:01:50 -->
 <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="MarksReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c94cf32b-b8af-4c52-b787-3e35457c3400">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="reg data"/>
<queryString>
    <![CDATA[SELECT name,physics,chemistry,maths,biology from marks;]]>
</queryString>
<field name="name" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="physics" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="chemistry" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="maths" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="biology" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="51" splitType="Stretch">
        <staticText>
            <reportElement x="80" y="20" width="300" height="30" uuid="424d7727-b45d-4417-9a98-9d5f0757ab36"/>
            <textElement textAlignment="Justified">
                <font size="14" isBold="true" isUnderline="true"/>
            </textElement>
            <text><![CDATA[MARKS OF STUDENTS]]></text>
        </staticText>
    </band>
</title>
<columnHeader>
    <band height="63" splitType="Stretch">
        <staticText>
            <reportElement x="0" y="30" width="80" height="30" uuid="a73606af-a42b-403b-8a29-fac31fbdfa7c"/>
            <text><![CDATA[name]]></text>
        </staticText>
        <staticText>
            <reportElement x="80" y="30" width="80" height="30" uuid="dbb8e810-b883-4cbd-bc57-259e7076cf39"/>
            <text><![CDATA[physics]]></text>
        </staticText>
        <staticText>
            <reportElement x="160" y="30" width="70" height="30" uuid="18b70e45-9cdf-45d2-bd2a-81b6f6863237"/>
            <text><![CDATA[chemistry]]></text>
        </staticText>
        <staticText>
            <reportElement x="230" y="30" width="70" height="30" uuid="0cca7051-fa1e-4e63-8ac7-116dedbf97a3"/>
            <text><![CDATA[maths]]></text>
        </staticText>
        <staticText>
            <reportElement x="300" y="30" width="70" height="30" uuid="b88ece10-c334-4a95-9495-2f044782c095"/>
            <text><![CDATA[biology]]></text>
        </staticText>
        <staticText>
            <reportElement x="370" y="30" width="100" height="30" uuid="7f575c71-202f-41f9-87cd-13264574defe"/>
            <text><![CDATA[average]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
    <band height="125" splitType="Stretch">
        <textField>
            <reportElement x="0" y="11" width="80" height="30" uuid="9bc76bda-7b64-4bda-b484-a0ca301702ad"/>
            <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="80" y="10" width="80" height="30" uuid="42eafc88-0e65-423f-9b38-e25ea4eb775e"/>
            <textFieldExpression><![CDATA[$F{physics}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="160" y="10" width="70" height="30" uuid="7656ef9f-2e99-4b57-a87b-6412d3ab5bb9"/>
            <textFieldExpression><![CDATA[$F{chemistry}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="230" y="10" width="70" height="30" uuid="f171900c-8342-443a-9a26-5049b8840134"/>
            <textFieldExpression><![CDATA[$F{maths}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="300" y="10" width="70" height="30" uuid="426d26eb-9d85-4ba2-836a-339928967353"/>
            <textFieldExpression><![CDATA[$F{biology}]]></textFieldExpression>
        </textField>
        <subreport>
            <reportElement x="370" y="0" width="95" height="20" uuid="75acf702-90cb-44c9-b819-270b0e2c128a">
                <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
            </reportElement>
            <subreportParameter name="name">
                <subreportParameterExpression><![CDATA[$F{name}]]></subreportParameterExpression>
            </subreportParameter>
            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
            <subreportExpression><![CDATA["AverageSub.jasper"]]></subreportExpression>
        </subreport>
    </band>
</detail>
我经常遇到的错误是:exceptionnet.sf.jasperreports.engine.jreexception:Resource找不到:AverageSub.jasper,其中AverageSub.jasper是我的子报表名


伙计们,我需要你们的帮助,我必须在明天之前把这个交给我的老师。谢谢

假设存在AverageSub.jasper

如果没有,您可能忘记编译AverageSub.jrxml

在jasper报表中,您应该将绝对路径与图像和子报表一起使用,因此您需要通过其绝对路径(完整路径)调用子报表

是的

在jrxml中添加参数

<parameter name="basePath" class="java.lang.String"></parameter>

在子报表调用中

<subreportExpression><![CDATA[$P{basePath}+"AverageSub.jasper"]]></subreportExpression>

<subreportExpression><![CDATA["C:/Users/Sony/workspace/StudentRegiForm/AverageSub.jasper"]]></subreportExpression>
hm.put("basePath","C:/Users/Sony/workspace/StudentRegiForm/")
<parameter name="basePath" class="java.lang.String"></parameter>
<subreportExpression><![CDATA[$P{basePath}+"AverageSub.jasper"]]></subreportExpression>