• Post Reply Bookmark Topic Watch Topic
  • New Topic

request.getSession() is null  RSS feed

 
ema kacurkova
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone, i will appreciate if someone help me with the following problem.
I have a jasper report which i fill in a PrintingBean and its all good. The moment i clicked on a print preview button (opening the applet) my app throws a null pointer exception at
PrintingBean bean = (PrintingBean) request.getSession().getAttribute("printMB"); line....
it seems like it makes new session (but i cant see that on gui, its all good). My manageBean is a SessionScoped. This is my whole method:

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();
}
}

Thanks Ema

 
thippe swamy
Greenhorn
Posts: 10
Chrome Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try creating the session object in aseparate line and use that object.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!