Hi,
Wouldn't your conditional statement cause a null pointer exception if s is
null? Try it!
I do this:
...
if(null != s) {
if(s.length() != 0) {
// it's not null and it's not empty
}
}
Regards,
Mark
> -----Original Message-----
> From: Richard Clark [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, 6 January 2000 10:34
> To: [EMAIL PROTECTED]
> Subject: Re: Checking for null
>
> To check for both null and zero length:
>
> String s = req.getParameter("value");
> if (null == s || s.length() == 0) {
> // it's null or empty
> }
>
> For just null, use (null == s)
>
> ...Richard
>
> -----Original Message-----
> From: John McDonald [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 05, 2000 3:03 PM
> To: [EMAIL PROTECTED]
> Subject: [SERVLET-INTEREST] Checking for null
>
>
> I am retrieving a value from a web page with req.getParameter("value").
> How
> do I check if the string is null without getting a null pointer exception.
> Any ideas would be helpful.
>
> __________________________________________________________________________
> _
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html