This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes Some issue with unBound.  getting NullPointerException. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Some issue with unBound.  getting NullPointerException." Watch "Some issue with unBound.  getting NullPointerException." New topic
Author

Some issue with unBound. getting NullPointerException.

Yuva Kumar
Greenhorn

Joined: Jul 18, 2008
Posts: 12
Hi

I have a Servlet which implements HttpSessionBindingListener and has methods valueBound() and valueUnbound().

In my servlet, I have a function, which sets the servlet object to session upon which the valueBound function gets called internally.

But in valueBound(), I would like to call a function of an object which was already initialized in the init method itself. But I am getting NullPointerException (boObj is becoming null).

If instead of making a call to the function inside the object, I make the function available locally in the servlet, it is working fine.

Also, in that function, I am trying to insert a record in the table to store the logged in user id and session id. This is getting called only for the first user who logs in, but not for subsequent user login.

Could someone pl suggest as w.r.t the above issues, ie.
1) boObj is becoming null in valueBound()
2) After making function available locally, the function is called only once for the first user session and not for all user's sessions.

Thanks in advance for all your suggsions.

Regards,
Yuva

I have the code snippet as follows

n
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

I don't understand two things. Is your servlet (which implements GenericServlet or HttpServlet) also implementing HttpSessionBindingListener. If yes, then there will be two instances of your class, one will act as a servlet and one as session binding event listener. The init method will only be called on the servlet and not on the listener so the object boObj will be null.

Also I don't understand this statement

In my servlet, I have a function, which sets the servlet object to session upon which the valueBound function gets called internally.


Are you setting the servlet object into the session or just adding a normal object as attribute into the session...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
 
subject: Some issue with unBound. getting NullPointerException.