我正在使用spring mvc的jasper报告开发报告。
点击查看按钮时出现以下错误,显示空白页。
net.sf.jasperreports.engine.JRException: org.xml.sax.SAXParseException; lineNumber: 59; columnNumber: 14; cvc-complex-type.2.1: Element 'property' must have no character or element information item [children], because the type's content type is empty.
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:247)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:230)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:218)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:171)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:448)
at com.asd.cms.service.ReportService.getReport(ReportService.java:137)
at com.asd.cms.service.ReportService.generateReport(ReportService.java:58)
at com.asd.cms.controller.KGDLCReport.viewReport(KGDLCReport.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
............................................... ............`
我的KGDLCReport.java代码:
com.asd.cms.controller.KGDLCReport.viewReport(KGDLCReport.java:70)
@RequestMapping("/userWiseReportKGDLC")
public void viewReport(HttpServletRequest request, HttpServletResponse response) {
String dateFrom = request.getParameter("dateFrom");
String dateTo = request.getParameter("dateTo");
String outputFormat = request.getParameter("outputFormat");
Map<String,Object> param = new HashMap<String,Object>();
param.put("dateFrom", dateFrom);
param.put("dateTo", dateTo);
String path = request.getSession().getServletContext().getRealPath("/resources/jasper/KGDCL_Report1.jrxml");
**KGDLCReport.java:70** -> reportService.generateReport(path, outputFormat, param, response);
}
com.asd.cms.service.ReportService.generateReport(ReportService.java:58)
public void generateReport(String path, String outputFormat, Map<String, Object> param, HttpServletResponse res){
try{
if(new File(path).exists()){
JasperPrint jp = getReport(path, param); // Line: 58
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//String outputFormat = req.getParameter("outputFormat");
if(outputFormat.equals("pdf")){
JasperExportManager.exportReportToPdfStream(jp, baos);
.............
}
}
com.asd.cms.service.ReportService.getReport(ReportService.java:137)
public JasperPrint getReport(String path, Map<String, Object> parameters) throws SQLException{
JasperPrint print = new JasperPrint();
JasperReport report;
try {
System.out.println("Path inside ReportService.java line 135"+path);
report = JasperCompileManager.compileReport(path); //Line: 137
print = JasperFillManager.fillReport(report, parameters, jdbcTemplate.getDataSource().getConnection());
} catch (JRException e) {
e.printStackTrace();
}
return print;
}
哪一个可能是导致错误的原因? 提前谢谢。
答案 0 :(得分:0)
在做了一些R&amp; D之后我发现了问题。问题出现在报告页面中。 Java代码没问题。 JRXmlLoader can't load xml of the report page accurately. So SAXParser wasn't able to parse xml.
这就是我收到错误的原因。