누군가가 다음 문제를 해결해 주시면 감사하겠습니다. 저는 재 스퍼 보고서를 가지고 있습니다.이 보고서는 PrintingBean
과 그 모두를 채 웁니다. 내 응용 프로그램에서 널 포인터 예외가 발생합니다 (애플릿을 열어) 나 인쇄 미리보기 버튼을 클릭하는 순간 : 그것은 새로운 세션 (하지만 GUI에 그것을 볼 수 있습니다처럼request.getSession() is null
if (bean.getPrintingDataList() != null && !bean.getPrintingDataList().isEmpty())
그것은 그것의 모든 것 좋은). 내 manageBean은 SessionScoped입니다. 이것은 내 모든 방법입니다.
private void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
JasperPrint jasperPrint = null;
try {
PrintingBean bean = (PrintingBean) request.getSession().getAttribute("printMB");
if (bean.getPrintingDataList() != null && !bean.getPrintingDataList().isEmpty()) {
jasperPrint = printManager.print(bean.getPrintingDataList());
}
} catch (Exception ex) {
Logger.getLogger(JasperPrintServlet.class.getName()).log(Level.SEVERE, null, ex);
}
if (jasperPrint != null) {
response.setContentType("application/octet-stream");
ServletOutputStream ouputStream = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(ouputStream);
oos.writeObject(jasperPrint);
oos.flush();
oos.close();
ouputStream.flush();
ouputStream.close();
}
}
그건 불가능합니다. 주어진 행에'null'을 반환하고,'bean'에 접근 한'if' 블록에서'NullPointerException'이 실제로'if' 블록에 던져지는 것을 실제로 의미하지 않습니까? 그러면 훨씬 더 의미가 생겨 응답 될 수 있습니다. – BalusC
그렇습니다. request.getSession()에 속성 (크기가 0)이없고 .getAttribute ("printMB")가 전혀 존재하지 않으므로 네가 맞으면 NPE를 if 블록에 던집니다. 왜 그리고 어떻게이 문제를 해결할 수 있는지 알고 있습니까? 시간 내 주셔서 감사합니다. – falconiki