日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Java-Jasper報(bào)告空白頁

 印度阿三17 2019-10-25

我的jrxml和Java代碼如下.我正在嘗試使用一些文本和值創(chuàng)建報(bào)告.但是,將生成空白報(bào)告.我正在粘貼地圖以將報(bào)告填充為參數(shù).我必須添加4-5條靜態(tài)行,然后添加一個(gè)動(dòng)態(tài)變量.我在詳細(xì)的樂隊(duì)中添加了這些東西.錯(cuò)了什么

    <?xml version="1.0" encoding="UTF-8"  ?>
    <!-- Created with iReport - A designer for JasperReports -->
    <!DOCTYPE jasperReport PUBLIC "http://JasperReports//DTD Report Design//EN" "http://jasperreports./dtds/jasperreport.dtd">
    <jasperReport
             name="Untitled_report_2"
             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="0" />
        <property name="ireport.encoding" value="UTF-8" />
        <import value="java.util.*" />
        <import value="net.sf.jasperreports.engine.*" />
        <import value="net.sf.jasperreports.engine.data.*" />


        <field name="Field" 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" >
                </band>
            </columnHeader>
            <detail>
                <band height="100"  isSplitAllowed="true" >
                    <staticText>
                        <reportElement
                            x="20"
                            y="10"
                            width="180"
                            height="30"
                            key="staticText-1"/>
                        <box></box>
                        <textElement>
                            <font/>
                        </textElement>
                    <text><![CDATA[4-5 lines text]]></text>
                    </staticText>
                    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                        <reportElement
                            x="20"
                            y="40"
                            width="60"
                            height="20"
                            key="textField-1"/>
                        <box></box>
                        <textElement>
                            <font/>
                        </textElement>
                    <textFieldExpression   class="java.lang.String"><![CDATA[$F{Field}]]></textFieldExpression>
                    </textField>
                    <staticText>
                        <reportElement
                            x="20"
                            y="70"
                            width="160"
                            height="30"
                            key="staticText-2"/>
                        <box></box>
                        <textElement>
                            <font/>
                        </textElement>
                    <text><![CDATA[4-5 lines text]]></text>
                    </staticText>
                </band>
            </detail>
            <columnFooter>
                <band height="30"  isSplitAllowed="true" >
                </band>
            </columnFooter>
            <pageFooter>
                <band height="50"  isSplitAllowed="true" >
                </band>
            </pageFooter>
            <lastPageFooter>
                <band height="50"  isSplitAllowed="true" >
                </band>
            </lastPageFooter>
            <summary>
                <band height="50"  isSplitAllowed="true" >
                </band>
            </summary>
    </jasperReport>

Java代碼:

    InputStream fileInput = getApplicationContext().getResource("/WEB-INF/reports/myjrxml.jrxml").getInputStream();
    JasperReport jasperReport = JasperCompileManager.compileReport(fileInput);
    HashMap map = new HashMap();
    map.put("Field", "test");
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map);
    byte[] output1 = JasperExportManager.exportReportToPdf(jasperPrint); 
    String filename = "d:/test.pdf";
    FileOutputStream fo = new FileOutputStream(filename);
    fo.write(output1);
    fo.close();

解決方法:

您正在將報(bào)告數(shù)據(jù)與參數(shù)混淆.我看不到您有任何報(bào)告數(shù)據(jù),這就是為什么您得到空報(bào)告的原因.此外,您要填充一個(gè)名為“ Field”的參數(shù),而不是實(shí)際的報(bào)告數(shù)據(jù).因此,您需要在報(bào)表中創(chuàng)建一個(gè)名為“字段”的參數(shù),然后在詳細(xì)信息區(qū)域中對其進(jìn)行引用,或者您需要將報(bào)表數(shù)據(jù)傳遞到報(bào)表中,例如

JRBeanCollectionDataSource data = new JRBeanCollectionDataSource(dataSet);
jasperPrint = JasperFillManager.fillReport(jasperReport, parameterMap, data);

其中dataSet是一個(gè)集合,例如List<?>.在列表中,您將擁有一個(gè)對象,其中屬性之一是字段.

來源:https://www./content-1-519251.html

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多