It's not a secret anymore!*
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 Murach's Java Servlets and JSP this week in the Servlets 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>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Null exception retrieving session attribute
 
Similar Threads
stringbuffer :nullpointerexception
<jsp:useBean>inside the scripting block
jboss, datasource naming and lookup error
How are Standard bean action tags useful
How to use Mark and reset for inputstream ?