我想使用jasper报告库获取报告,但出现错误 “ net.sf.jasperreports.engine.JRException:com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:1字节UTF-8序列的无效字节1。”
private JasperPrint prepareReport(EnumList.JRList report) {
try {
Connection conn = getConnection();
String jasperResource = "/reports/" + report.getName() + ".jasper";
InputStream jasperStream = getClass().getResourceAsStream(jasperResource);
//InputStreamReader inputStreamReader = new InputStreamReader(jasperStream, Charset.forName("UTF-8"));
JasperReport jasperReport =
JasperCompileManager.compileReport(jasperStream);
Map<String, Object> param = new HashMap<String, Object>();
JRDesignStyle jrDesignStyle = new JRDesignStyle();
//jrDesignStyle.setPdfEncoding("UTF-8");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, param, conn);
return jasperPrint;
} catch (Exception e) {
System.out.println("reportPrepareError: " + report.getName());
return null;
}
}
public static JasperReport compileReport(InputStream inputStream) throws JRException
{
return getDefaultInstance().compile(inputStream);
}
public JasperReport compile(InputStream inputStream) throws JRException {
JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
return this.compile(jasperDesign);
}
答案 0 :(得分:1)
.jasper文件通常将包含一个已编译的报告。
因此您不需要JasperCompileManager.compileReport(jasperStream)
,但
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperStream);