Grails - Jasper 插件 - .jasper 文件的 1 字节 UTF-8 序列错误的无效字节 1

发布于 2024-10-04 19:19:46 字数 3004 浏览 0 评论 0原文

我正在使用 Grails 1.3.5、SQL Server 2005、iReports 3.7.6、Jasper 插件 1.1.3。在我的 GSP 页面中,我将 jasperReprt 标记指定为:

<g:jasperReport jasper="report1" format="PDF">
<input type="hidden" name="test_id" id="test_id"/>
<input type="hidden" name="order_no" id="order_no" />   
</g:jasperReport>

对于开发,在 Config.groovy 中,我指定了

jasper.dir.reports = './reports'

创建和保存新报告时,在 reports 文件夹中创建了两个文件,即 report.jrxml 和 report.jasper。

当在 IE 或 Firefox 中单击 PDF 图标时,会抛出 500 服务器错误,下面是堆栈跟踪。

[2010-11-27 01:13:14.998] 错误 groovy.grails.web.errors.GrailsExceptionResolver 1 字节 UTF-8 序列的字节 1 无效。 com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:1 字节 UTF-8 序列的字节 1 无效。 在 com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:684) 在 com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:554) 在 com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742) at

但是,如果我删除 report1.jasper,则单击 PDF 图标时不再抛出错误,并且 PDF 报告显示正常。

这是正确的方法吗?

  • 我的第二个问题是使用子报告。子报告与主报告位于同一文件夹中。但是当从应用程序执行报告时,会抛出以下错误:

    [2010-11-27 01:30:27.556] 错误 groovy.grails.web.errors.GrailsExceptionResolver 无法从位置加载对象:./reports\report1sub_report.jasper net.sf.jasperreports.engine.JRException:无法从位置加载对象:./reports\urine_routinepatent_details_sub_report.jasper 在net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:262) 在net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:301) 在 net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:327)

它找不到子报告。我该如何修复它?

谢谢。 杰·钱德兰.

编辑: 我一直在寻找,但仍然找不到合适的解决方案。所以我做了一些尝试和错误。我发现,删除 report1.jasper 并将 jasper.jrxml 留在报告目录中就可以正常工作,正如我之前所说。

对于子报告问题:它给出错误 无法从位置加载对象:./reports\report1sub_report.jasper 由于某些奇怪的原因,主报告名称 report 是附加到名称 sub_report.jasper 并正在查找名为 report1sub_report.jasper 的文件

,因此我在 reports 文件夹下创建了一个子文件夹,然后将其命名为 report1 并更新了 report1.jrxml 文件

<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "\\sub_report.jasper"]]></subreportExpression>

我必须添加额外的 \\ 斜线,即使“SUBREPORT_DIR”参数具有 \\路径末尾的斜杠如下所示。

<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA["F:\\Workspace\\SpringSource2.5.0\\GrailsProjec\\reports\\report1\\"]]></defaultValueExpression>
</parameter>

请注意末尾的 \\。我不知道为什么它没有被附加!

另一种方法是仅更改 sub_report.jasper 中的子报告名称 到 report1sub_report.jasper!!! :)

我已经在生产模式下对此进行了测试,并且工作正常。我不确定这是否是这样做的方法,但所有其他可能的解决方案都不适合我。

反馈将会非常有帮助。

I am using Grails 1.3.5, SQL Server 2005, iReports 3.7.6, Jasper Plugin 1.1.3. In my GSP page I have given the jasperReprt tag as:

<g:jasperReport jasper="report1" format="PDF">
<input type="hidden" name="test_id" id="test_id"/>
<input type="hidden" name="order_no" id="order_no" />   
</g:jasperReport>

For development, in Config.groovy I have specified the

jasper.dir.reports = './reports'

There are two files created in the reports folder when a new report is created and saved, i.e. report.jrxml and report.jasper.

When clicked on the PDF icon in IE or Firefox, an 500 server error is thrown and below is stack trace.

[2010-11-27 01:13:14.998] ERROR groovy.grails.web.errors.GrailsExceptionResolver Invalid byte 1 of 1-byte UTF-8 sequence.
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:684)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:554)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742)
at

But if I delete the report1.jasper, the error is no longer thrown when PDF icon is clicked and the PDF report is shown fine.

Is this the correct way to do it?

  • My second issue is with using Sub Reports. Sub report is in the same folder as the main report. But When the report is executed from the application, below error is thrown:

    [2010-11-27 01:30:27.556] ERROR groovy.grails.web.errors.GrailsExceptionResolver Could not load object from location : ./reports\report1sub_report.jasper
    net.sf.jasperreports.engine.JRException: Could not load object from location : ./reports\urine_routinepatient_details_sub_report.jasper
    at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:262)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:301)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:327)

It does not find the sub report. How can I fix it?

Thank you.
Jay Chandran.

Edit:
I have been searching during this whole time, but still could not find a proper solution. So I did some trial and error. I figured out that, deleting report1.jasper and just leaving jasper.jrxml in the report directory works just fine as I said earlier.

For the sub-report issue: It was giving error Could not load object from location : ./reports\report1sub_report.jasper For some strange reason, the main report name report was getting appended to the name sub_report.jasper and was looking for a file named report1sub_report.jasper

So I created a sub-folder under reports folder and named it report1 and updated report1.jrxml file

<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "\\sub_report.jasper"]]></subreportExpression>

I had to add the extra \\ slash even though the "SUBREPORT_DIR" parameter had \\ the slashes at the end of the path as shown below.

<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA["F:\\Workspace\\SpringSource2.5.0\\GrailsProjec\\reports\\report1\\"]]></defaultValueExpression>
</parameter>

Notice the \\ at the end. I don't know why it was not getting appended!

Another way would have been to just change the sub-report name from sub_report.jasper
to report1sub_report.jasper!!! :)

I have tested this in production mode and it works fine. I am not sure if this is the way to do it, but all other possible solutions did not work for me.

Feedback will be very helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

金橙橙 2024-10-11 19:19:46

我假设你这里有版本冲突。 iReport 存储 JRXML 文件,并且似乎会自动将它们编译为 .jasper。 Grails Jasper 插件选择了编译变体并遇到了麻烦。因此尝试在 ireport 中禁用编译输出。

Grails Jasper插件1.1.3内部使用Jasper 3.7.4,使用的ireport是3.7.6。

关于子报告:不知道。

I assume you have a version conflict here. iReport stores JRXML files and seems to compile them automatically to .jasper. The Grails Jasper plugin picks up the compile variant and gets into trouble with it. So try to disable compiled output in ireport.

The Grails Jasper plugin 1.1.3 uses internally Jasper 3.7.4, the used ireport is 3.7.6.

Regarding the sub reports: no idea.

等待圉鍢 2024-10-11 19:19:46

MalformedByteSequenceException 是由字符编码冲突引起的。我建议在任何地方都使用 UTF-8 而不是 Windows 的 Win-1252(类似于 ISO-8859-1)。

在 Jasper 的 etc/ireport.conf 文件中,将 default_options 更改为:(

default_options="-J-Dfile.encoding=UTF-8 -J-Xms24m -J-Xmx64m"

其中 XmsXmx 是不相关的内存如果该配置条目有默认设置,您可以超越它们,否则,只需将它们保留即可。)

请参阅 此论坛帖子了解替代配置。

至于子报表的错误,看看反斜杠 \ 可能是错误的。

The MalformedByteSequenceException is caused by a character encoding conflict. I'd suggest to use UTF-8 instead of Windows' Win-1252 (similar to ISO-8859-1) everywhere.

In Jasper's etc/ireport.conf file, change the default_options to:

default_options="-J-Dfile.encoding=UTF-8 -J-Xms24m -J-Xmx64m"

(Where Xms and Xmx are unrelated memory settings. If there are default settings with that config entry, you can overtake them, else, just leave them out.)

See this forum thread for alternative configurations.

As for the error with subreports, take a look at the backslash \ that's probably wrong.

编辑:有一些关于两个问题的信息可能有助于
http://grails.org/plugin/jasper#faqTab

我希望我能帮助其中之一问题:哪一个与子报告目录相关。
问题是插件代码将 SUBREPORT_DIR 设置为主报告的完整文件路径,包括其名称。但是,代码尊重用户提供的具有相同名称的参数,因此,如果您使用除 null 之外的任何值填充此参数,插件将使用它。

例如,如果您直接链接 jasper 控制器,您可以执行以下操作:

def renderAs(data,format) {
    def reportParams=params.clone()
    reportParams["_format"]=reportParams["_format"]?:"${format.toUpperCase()}"
    reportParams["SUBREPORT_DIR"]=CH.config.jasper.dir.reports+"/"
    chain(controller:'jasper',action:'index',model:[data:[]+data],params:reportParams)
}

在您的场景中,一个(丑陋的)选项将创建一个名为 SUBREPORT_DIR 的隐藏输入,并指定所需的值。我会以其他方式填写参数。

编辑
另一个烦人的问题是我们必须将主报告和编译的子报告放在哪里:

  • 当您使用 run-app 运行应用程序时,如果您将它们全部放在与 CH.config.jasper.dir.reports 同名的文件夹中,它们就会工作(reportDir) 在 grails 应用程序的根目录中。
  • 但是如果你想部署一个war,你必须将主报告放在war文件根目录的reportDir文件夹中,并将编译的子报告放在WEB-INF/classes/reportDir中。

我选择将所有文件保留在 grailsApp/reports 中,并将资源复制到 war grails 任务中的适当文件夹中。在我的 BuildConfig.groovy 中,我添加了(reportDir 是“reports”):

grails.war.resources = { stagingDir,args ->
    def classpathDir="${stagingDir}/WEB-INF/classes"
    copy(toDir:"${stagingDir}/reports") {
        fileset(dir:"reports",includes:"**")
    }
    copy(toDir:"${classpathDir}/reports") {
        fileset(dir:"reports",excludes:"**.jrxml")
    }
} 

希望有帮助。

EDIT : There is some information about two issues which maybe could help in
http://grails.org/plugin/jasper#faqTab

i hope i can help with one of the issues: which one related with subreports dir.
The problem is the plugin code sets SUBREPORT_DIR to the complete file path of main report, including its name. However the code honour the user provided param with the same name, so if you fill this param with whatever value except null the plugin will use it.

For example if you chain directly the jasper controller you can do:

def renderAs(data,format) {
    def reportParams=params.clone()
    reportParams["_format"]=reportParams["_format"]?:"${format.toUpperCase()}"
    reportParams["SUBREPORT_DIR"]=CH.config.jasper.dir.reports+"/"
    chain(controller:'jasper',action:'index',model:[data:[]+data],params:reportParams)
}

In your scenario an (ugly) option would be create an hidden input with name SUBREPORT_DIR and value the desired one. I would fill the paremeter in other way.

EDIT:
Another annoying problem is where do we have to put the main reports and compiled subreports:

  • When you run the app with run-app they work if you put them all in a folder with the same name as CH.config.jasper.dir.reports(reportDir) in the root of the grails app.
  • But if you want to deploy a war you have to put the main reports in a folder reportDir in the root of war file and compiled subreports in WEB-INF/classes/reportDir.

I've opted to keep all files in grailsApp/reports and copy the resources in the appropiate folders in the war grails task. In my BuildConfig.groovy i've added (reportDir is "reports"):

grails.war.resources = { stagingDir,args ->
    def classpathDir="${stagingDir}/WEB-INF/classes"
    copy(toDir:"${stagingDir}/reports") {
        fileset(dir:"reports",includes:"**")
    }
    copy(toDir:"${classpathDir}/reports") {
        fileset(dir:"reports",excludes:"**.jrxml")
    }
} 

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文