【发布时间】:2012-07-02 15:42:31
【问题描述】:
我遇到了这个问题,必须在我的 grails 应用程序上显示我的 jasper 报告。
在应用程序上,我使用以下命令安装了 jasper 插件:grails> install-plugin jasper
我创建了 sample.jrxml 具有这种上下文:
<?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="student" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.2100000000000002"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="181" y="0" width="212" height="37"/>
<textElement textAlignment="Center">
<font size="24"/>
</textElement>
<text><![CDATA[Portal Student List]]></text>
</staticText>
</band>
</title>
<columnHeader>
<band height="26"/>
</columnHeader>
<detail>
<band height="98" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="43" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch">
<staticText>
<reportElement x="238" y="0" width="100" height="20"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Copyright]]></text>
</staticText>
</band>
</pageFooter>
</jasperReport>
我使用 Jasper 标记 <g:jasperReport jasper="student" format="PDF"/> 调用报告,或者创建一个新的闭包,使用此代码将 .pdf 文件直接显示到浏览器:
def report() {
def reportDef = new JasperReportDef(folder: 'reports', name:'student.jrxml', fileFormat: JasperExportFormat.PDF_FORMAT)
reportDef.contentStream = jasperService.generateReport(reportDef)
response.contentType = reportDef.fileFormat.mimeTyp
response.characterEncoding = 'UTF-8'
response.outputStream << reportDef.contentStream.toByteArray()
}
使用的任何一种方法都返回一个空白页。
我该如何解决这个问题?
谢谢
【问题讨论】:
-
你解决过这个问题吗?我有同样的问题:/
-
只需按照 Grails 网站上 Jasper 的插件文档进行操作即可。
-
如果您的意思是grails.org/plugin/jasper,那么我确实遵循了这一点。您能否分享相关的 BuildConfig.groovy 片段(“依赖项”和“插件”)?我不确定我是否使用了所有正确的版本,因为它不能通过添加“compile ':jasper:1.6.1'”来开箱即用。
标签: grails jasper-reports ireport