The best way to deal with this problem in a Struts application is to put code at the beginning of each action class that checks to see whether a specific object exists in the session or not. In most cases, you have an object such as a User object indicating that the user is signed on to the system. If you don't already have such an object, create one. Once you have an object that you know should always be in the session, check for it like this:
Show us your code as well as the stack trace you're getting from the error. If you really did change it to "if (user == null)", there's no way that statement could throw a null pointer exception. Check the line number on the stack trace to see specifically which line is throwing the exception. I'm guessing it will be a different line in your code.
Thanks Merill and Naseem, Got it. The problem was - Before performing the null comparison i.e. (user==null), i had another session variable named 'StationId'-which i was storing in another String variable. i.e. stnId=(String)request.getSession().getAttribute("StationId");
That's why it was giving null pointer exception.
I just put the 'null comparison' code before the above code. And now its working.
Thanks once again.
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop