File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Prevent 'null' in sessions.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Prevent Watch "Prevent New topic

Prevent 'null' in sessions..

Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
Assume I have a jsp page with the following code :
String name = (String) session.getValue("myName");
Now I execute it right out of the box without the myName session ever being created.. How can I prevent a nullpointerexception here ?
I've theoritically understood the true arguement but never got around to using it.
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

Not sure if this is what you want, but one easy answer is:

Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
Thats what I use.. actually the tertiary operator to populate name if the session is null..
What i was interested in was knowing if there is some kind of boolean true i can pass to getValue to automatically move " " or 0 to name if its null
guess not
I agree. Here's the link:
subject: Prevent 'null' in sessions..
It's not a secret anymore!