You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by John Coonrod <jc...@thp.org> on 2000/09/14 17:04:08 UTC

Help! How to deal with null session variables??

I frequently crash pages with nullPointerExceptions when trying to get 
session variables into a string.

What I want is:

String MyVal=session.getValue("x").toString();

and if x isn't there, I'd like ""





Re: Help! How to deal with null session variables??

Posted by Holger Klawitter <ho...@klawitter.de>.
> String MyVal=session.getValue("x").toString();

You can initialize the session with empty strings,
or write your own reader function.

By the way: getValue() is deprecated, use getAttribute().

Regards,
Mit freundlichem Gruß,
	Holger Klawitter
--
Holger Klawitter                                    +49 (0)251 484 0637
holger@klawitter.de                            http://www.klawitter.de/



RE: Help! How to deal with null session variables??

Posted by Mike Bremford <mi...@paperx.com>.
String MyVal=(session.getValue("x")!=null ? session.getValue("x").toString()
: "");

:-)

Cheers... Mike

> -----Original Message-----
> From: John Coonrod [mailto:jc@thp.org]
> Sent: 14 September 2000 16:04
> To: tomcat-user@jakarta.apache.org
> Subject: Help! How to deal with null session variables??
>
>
> I frequently crash pages with nullPointerExceptions when
> trying to get
> session variables into a string.
>
> What I want is:
>
> String MyVal=session.getValue("x").toString();
>
> and if x isn't there, I'd like ""
>
>
>
>
>