aspose file tools
The moose likes Servlets and the fly likes Some issue with unBound.  getting NullPointerException. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply 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
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Some issue with unBound. getting NullPointerException.
 
Similar Threads
HttpSessionBindingListener
Problem with valueUnbound() of HttpSessionBindingListener
Regarding valueBound & valueUnbound events
How to know when a session is removed?
jsp-servletListener