我正在使用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
你檢查參數圖嗎?你看到靜態文本了嗎? –