繁体   English   中英

碧玉报告:空报告

[英]Jasper report :Empty report

我正在尝试通过发送参数来使用Jasper Reports生成PDF报告,但是报告始终为空,并且GlassFich中没有任何错误。另一个问题是报告的名称,当我编辑查询以添加参数时,我发现报告的名称为空。 我进行了很多搜索,但找不到问题。请帮忙。

index.html

  <form action="Task">
  <input type="text"  name="id" >
  </form>

Task.java

 int id=Integer.parseInt(request.getParameter("id"));

 try{
 Class.forName("com.mysql.jdbc.Driver");
 Connection      conn=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
Statement st = conn.createStatement();
File reportFile = new File("//report1.jasper");
Map param=new HashMap();
param.put("id", id);
byte[]bytes=JasperRunManager.runReportToPdf(reportFile.getPath(),param,conn);
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream outStream=response.getOutputStream();
outStream.write(bytes,0,bytes.length);
outStream.flush();
outStream.close();
}catch(Exception ex){
ex.printStackTrace();
}     

report1.xml

  <?xml version="1.0" encoding="UTF-8"?>
  <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="null" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="869aca66-1f7b-4e24-a8d8-090840222f22">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="parameter1" class="java.lang.Integer"/>
<queryString>
    <![CDATA[select * from task where id=$P{parameter1}]]>
</queryString>
<field name="id" class="java.lang.Integer">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="start_date" class="java.sql.Date">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="duration" class="java.lang.Integer">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="text" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>

<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="79" splitType="Stretch"/>
</title>
<columnHeader>
    <band height="61" splitType="Stretch">
        <staticText>
            <reportElement x="43" y="2" width="100" height="20" uuid="497fe8e3-98cf-4cd2-9841-11579f25a51b"/>
            <text><![CDATA[start_date]]></text>
        </staticText>
        <staticText>
            <reportElement x="195" y="2" width="100" height="20" uuid="d714a12d-4b7d-473f-adb3-34fb39eb99c5"/>
            <text><![CDATA[duration]]></text>
        </staticText>
        <staticText>
            <reportElement x="325" y="2" width="100" height="20" uuid="6cc1d4de-4bcc-45f0-b361-befd9b277e28"/>
            <text><![CDATA[text]]></text>
        </staticText>
        <staticText>
            <reportElement x="486" y="2" width="100" height="20" uuid="c5e7c67b-39c2-439b-971d-35f8d16bf6e6"/>
            <text><![CDATA[id]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
    <band height="125" splitType="Stretch">
        <textField>
            <reportElement x="43" y="19" width="100" height="20" uuid="e81d91a0-9a28-4609-9f7c-cf841e0475af"/>
            <textFieldExpression><![CDATA[$F{start_date}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="195" y="17" width="100" height="20" uuid="52ba1845-6feb-4ce0-b304-906c0c7c25df"/>
            <textFieldExpression><![CDATA[$F{duration}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="325" y="28" width="100" height="20" uuid="4d95ce91-4c97-482f-bb6b-880c3eab6b14"/>
            <textFieldExpression><![CDATA[$F{text}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="486" y="44" width="100" height="20" uuid="70b0a1b1-e6f8-4931-8afb-7ef4aedb5351"/>
            <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
        </textField>
    </band>
</detail>

xml编辑标签<jasperReport>并设置name参数,现在您的参数name="null"

更新:

您在报告中的参数名称为parameter1 ,并输入了代码

Map param=new HashMap();
param.put("id", id);

尝试这个:

Map param=new HashMap();
param.put("parameter1", id);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM