我使用jasper插件來獲得pdf格式的報告。我試圖使用這個例子獲取報告(http://grails.org/plugin/jasper)。要獲得以下使用的pdf格式的特定id信息碼。jasper grails報告
<div class="buttons">
<g:form>
<g:hiddenField name="id" value="${userManagementInstance?.id}" />
<span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
<span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
</g:form>
</div>
<g:jasperReport jasper="use" format="PDF" name="users">
<input type="hidden" name="id" value="${userManagementInstance?.id}" />
</g:jasperReport>
我在show.gsp頁面中使用了上面的代碼來獲取特定的id報告。
<?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="report name" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<style name="pagetitle" isDefault="false" fontName="SansSerif" fontSize="14"/>
<parameter name="id" isForPrompting="false" class="java.lang.String">
<defaultValueExpression><![CDATA["<parameter error>"]]></defaultValueExpression>
</parameter>
<queryString><![CDATA[select * from user_management where id =$P{id}]]></queryString>
<field name="id" class="java.lang.String"/>
<field name="user_id" class="java.lang.String"/>
<field name="user_name" class="java.lang.String"/>
<background>
<band/>
</background>
<title>
<band height="79">
<staticText>
<reportElement style="pagetitle" x="0" y="0" width="201" height="46"/>
<textElement/>
<text><![CDATA[all]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35"/>
</pageHeader>
<columnHeader>
<band height="61">
<staticText>
<reportElement key="staticText" x="0" y="39" width="100" height="20"/>
<textElement/>
<text><![CDATA[id]]></text>
</staticText>
<staticText>
<reportElement key="staticText" x="130" y="39" width="100" height="20"/>
<textElement/>
<text><![CDATA[userId]]></text>
</staticText>
<staticText>
<reportElement key="staticText" x="266" y="39" width="100" height="20"/>
<textElement/>
<text><![CDATA[userName]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="42">
<textField isBlankWhenNull="false" hyperlinkType="None">
<reportElement key="textField" x="0" y="15" width="130" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false" hyperlinkType="None">
<reportElement key="textField" x="130" y="15" width="136" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{user_id}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false" hyperlinkType="None">
<reportElement key="textField" x="266" y="15" width="130" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{user_name}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45"/>
</columnFooter>
<pageFooter>
<band height="54"/>
</pageFooter>
<summary>
<band height="42"/>
</summary>
</jasperReport>
我在web-apps/report文件夾中使用上面的代碼use.jasper。
Error 500: Executing action [index] of controller [org.codehaus.groovy.grails.plugins.jasper.JasperController] in plugin [jasper] caused exception: null
Servlet: grails
URI: /inventoryManagment/grails/jasper.dispatch
Exception Message: invalid stream header: 3C3F786D
Caused by: invalid stream header: 3C3F786D
Class: Unknown
At Line: [-1]
但是我得到的錯誤是無效的流頭:3C3F786D。 所以請指導我解決這個問題。
您是否在iReport中檢查了您的報告?它有效嗎? –
如何查看iReport中的報告。這是我的新概念,所以我問。如何知道它是否有效? – manu
您是否安裝了iReport?如果是的話,嘗試編譯模板並嘗試預覽它(通過'預覽'選項卡) –