JRException:1字节UTF-8序列的无效字节1 [英] JRException: Invalid byte 1 of 1-byte UTF-8 sequence

查看:113
本文介绍了JRException:1字节UTF-8序列的无效字节1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Jasper Reports生成报告,但是出现以下错误.

I am trying to generate a report using Jasper Reports, but I am getting the following error.

net.sf.jasperreports.engine.JRException:com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:1字节UTF-8序列的无效字节1.

net.sf.jasperreports.engine.JRException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

我正在使用以下Java代码:

I am using this Java code:

    List<Aluno> lista = alunoService.findAll();
    String path = req.getSession().getServletContext().getRealPath("WEB-INF");
    JasperReport report = JasperCompileManager.compileReport(path + "/relatorios/aluno.jasper");
    JasperPrint print = JasperFillManager.fillReport(report, null, new JRBeanCollectionDataSource(lista));
    JasperExportManager.exportReportToPdfFile(print, path + "/relatorios/teste.pdf");

尝试编译报告时发生错误:

The error is ocurring when try to compile report:

JasperReport report = JasperCompileManager.compileReport(path + "/relatorios/aluno.jasper");

aluno.jrxml文件的格式为UTF-8:

The aluno.jrxml file is in UTF-8 enconding:

<?xml version="1.0" encoding="UTF-8"?>

我已经研究了这个问题,但是他们都说原因是因为jrxml filw不在UTF-8编码中.如果有人可以帮助我,我真的很感谢.

I've researched this problem, but they all say that the reason is because the jrxml filw is not in UTF-8 enconding. If anyone could help me, I really thank.

使用 aluno.jrxml

Java code using aluno.jrxml

    List<Aluno> lista = alunoService.findAll();
    String path = req.getSession().getServletContext().getRealPath("WEB-INF");
    JasperDesign design = JRXmlLoader.load(path + "/relatorios/aluno.jrxml");
    JasperReport report = JasperCompileManager.compileReport(design);
    JasperPrint print = JasperFillManager.fillReport(report, null, new JRBeanCollectionDataSource(lista));
    JasperExportManager.exportReportToPdfFile(print, path + "/relatorios/teste.pdf"

推荐答案

在开始时您具有<?xml version ="1.0" encoding ="UTF-8"?> 的事实文件中的数字并不意味着该文件实际上是以UTF-8编码存储的,仅表示我发誓此文件具有这种编码".

The fact that you have <?xml version="1.0" encoding="UTF-8"?> at the beginning of your file doesn't mean that the file is actually stored in UTF-8 encoding, that just means "I swear this file has this encoding".

文件中是否包含经典ASCII以外的字符?(就像上面带有波浪号的西班牙语N吗?)

Do you have in your file characters other than the classic ASCII? (something like the Spanish N with a tilde on it?)

尝试使用适当的编辑器打开文件并再次保存,然后明确选择编码为UTF-8 AND ,然后查看文件中的特殊字符以查看它们是否仍然存在一样.

Try opening your file with a decent editor and save it again, choosing explicitly the encoding as UTF-8 AND after that have a look at your special characters inside your file to see if they are still the same.

这篇关于JRException:1字节UTF-8序列的无效字节1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆