Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session object = null?

 
Mellihoney Michael
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use a session obj in the servlet class BookServlet:

in the following method:

I use a session obj to store all info pre-setted in an array of java beans

I attempted to retrieve the obj in this session in another method in the same servlet class:

but it will generate a NullPointerException in runtime:

can anyone help to solve this problem?
many thanks....
[ January 17, 2004: Message edited by: Mellihoney Michael ]
 
Moorthi Ramasamy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mellihoney Michael:

Mellihoney,
Where did you get this session variable?. To get the current session use
HttpSession session = req.getSession(true);
then set your book list in this session using
session.setAttribute("BOOKLIST", newbooklist);
In this case, your session object won't be NULL in insertBookToSession() method.
Thanks,
Moorthi
 
Mellihoney Michael
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why?
 
Moorthi Ramasamy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is you action parameter of the request comes with a value of "SAVE" in the first request and "CREATE XML" in the second request??
I guess insertBookToSession(request) & generateDOM(request) methods are invoked in two different request based on the action parameter.
generateDOM(request)
HttpSession session= request.getSession(false);//this is the one throwing NULL POINTER
Object books = session.getAttribute("BOOKLIST");
I doubt whether cookie is enabled in your browser. Could you please add the following line and let me know what's the value you are getting.

if (insertBookToSession(request)) {
/******** LINES TO BE ADDED ******/
HttpSession session= request.getSession();
out.println(session.isNew());
/******** LINES TO BE ADDED ******/
response.sendRedirect("../jsp/Book.html");}else {response.sendRedirect("../jsp/ListFullError.html");}

Thanks,
Moorthi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic