wood burning stoves 2.0*
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: http://aspose.com/file-tools
subject: Prevent 'null' in sessions..
Similar Threads
struts 2 -- name matching when we retrieve attributes from Action class
How to set a property's value thats part of a ArrayList using Javascript.
[Strust2] [I8N] result action message.
unable to pass data in same package
using string value as a variable name