aspose file tools*
The moose likes Servlets and the fly likes Null exception retrieving session attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Null exception retrieving session attribute" Watch "Null exception retrieving session attribute" New topic
Author

Null exception retrieving session attribute

Mikey Kelly
Greenhorn

Joined: Aug 09, 2005
Posts: 18
I'm doing this from within my servlet:


I get a null pointer exception at the line marked **. The "sessionBean" attribute is not initialised at first, but shouldn't the expression just put null into sB without giving an exception?
What is a better approach?
Thanks,
M
Mikey Kelly
Greenhorn

Joined: Aug 09, 2005
Posts: 18
Sorry, I think I have the wrong line for the exception - time to dig around in Tomcat...

:roll:
Sravan Kumar
Ranch Hand

Joined: Sep 11, 2005
Posts: 121
The only way that line can throw a NullPointerException is when session is null. How do you get the session? If you have created it using request.getSession(false), and if a session does not already exist, it won't create a session and the 'session' object will be null.


keep smilin :: sravan<br /><a href="http://sravanpens.blogspot.com" target="_blank" rel="nofollow">I scribble here</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null exception retrieving session attribute