wood burning stoves 2.0*
The moose likes Servlets and the fly likes session object = null? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "session object = null?" Watch "session object = null?" New topic
Author

session object = null?

Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
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 ]

a beginner in java
Moorthi Ramasamy
Greenhorn

Joined: Jan 02, 2004
Posts: 15
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

Joined: Nov 27, 2002
Posts: 124

Why?
Moorthi Ramasamy
Greenhorn

Joined: Jan 02, 2004
Posts: 15
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session object = null?