Relative path for the Subreport

主宰稳场 提交于 2019-12-04 10:08:57
Halo

Well I got an answer.

You can't. You can't use relative paths for your subreports. You may try to compile the .jrxml files at runtime or something, but relative paths don't seem to work for the projects with external servers or file systems.

user444237

You can use:

Map paramater = new Hasmap();
paramater.put("SUBREPORT_DIR",source);// source is path your subreport

Keep all your jrxml in reports folder under resources(in classpath).

Parameter created :

<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["reports/"]]></defaultValueExpression>
    </parameter>

Subreport Element created:

<elementGroup>
                <subreport>
                    <reportElement uuid="60c50685-03c7-452b-b37a-dda4a2092d18" positionType="Float" mode="Transparent" x="15" y="567" width="517" height="200" isRemoveLineWhenBlank="true" backcolor="#FFFFFF"/>
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(yourList)]]></dataSourceExpression>
                    <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "your_subreport.jasper"]]></subreportExpression>
                </subreport>
            </elementGroup>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!