我正在使用iReport-4.1.1创建.jasper和.jrxml文件。我的文件在Webcontent/reports以XML作为输入的JasperReports --- Getiing Inputstream空指针异常
下面是我用来从jasper打开PDF的代码。我将XML作为输入。
InputStream reportStream = getServletConfig().getServletContext().getResourceAsStream("/reports/FUECReport.jasper");
JRXmlDataSource xmlDataSource = new JRXmlDataSource(stringToDom(xmlResult));
HashMap parameterMap = new HashMap();
parameterMap.put("TITLE_MSG_PARAM", fUECRptMsg);
parameterMap.put("SURVEY_YEAR_PARAM", surveyYear);
parameterMap.put("STATE_CODE_PARAM", fipsStateCode);
JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, parameterMap,xmlDataSource);
response.setContentType("application/pdf");
servletOutputStream.flush();
servletOutputStream.close();
//this is the function that is converting the xmlsource to Document
public static Document stringToDom(String xmlSource) throws SAXException, ParserConfigurationException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(new InputSource(new StringReader(xmlSource)));
}
当我跑了,我在该行得到一个空指针异常:
JasperRunManager.runReportToPdfStream(*reportStream*,servletOutputStream, parameterMap,xmlDataSource);
说reportStream是空
有人请让我知道问题出在哪里。
当我从ireport运行并编译时,我能够成功打开PDF。
感谢
GK
FUECReport.jasper文件位于正确的位置。我将InputStream对象从reportStream更改为reportStream1。我还使用InputStreamReader来检查输入流是否正确。这是正确的,我检查。现在我得到一个异常,net.sf.jasperreports.engine.JRException:从InputStream加载对象时出错........引起:java.io.EOFException – user1015388
我能够克服这个问题,但现在PDF打开(从runReportToPdfStream)所有的值为NULL。我在PDF中看不到任何数据。该列的所有值均为NULL。 – user1015388
你检查参数图吗?你看到静态文本了吗? –