Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null exception retrieving session attribute

 
Mikey Kelly
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I think I have the wrong line for the exception - time to dig around in Tomcat...

:roll:
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic