On Wed, 4 Apr 2001, Mike Hulse wrote:

> It was sort of correct. The whole thin should have been
>
>                     String p1= String.valueOf(p);
>                     if(p1.equals("null"))......

No, that's not correct either.  The above is syntactially valid, but
what you're doing is checking whether the parameter has the value
"null" (unfortunately, there's a bit of confusion here, because, in
Java, when a String that is null is printed, "null" is printed, so,
from that alone, it is indistinguishable from a String whose value
actually is "null").  Also, getParameter() returns a string, so p is
already a String, so you don't need to do that convoluted

  String p1= String.valueOf(p);

you can just test p directly.

Once again, the proper way to check whether a return value from
getParameter() is non-null and non-empty is:

if (p != null && ! p.equals(""))

or

if (p != null && p.length() > 0)


> -----Original Message-----
> From: Jay Burgess <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
> Date: Wednesday, April 04, 2001 8:32 AM
> Subject: Re: Simple Problem....
>
>
> >Your response is not correct.  If p is null, then there is no object, so
> >there is no equals() method to call.  You'll get NullPointerException if
> >you try to execute your example and p is null.
> >
> >Jay
> >
> >-----Original Message-----
> >From: Poornima Visvesvaran [mailto:[EMAIL PROTECTED]]
> >Sent: Wednesday, April 04, 2001 7:00 AM
> >To: [EMAIL PROTECTED]
> >Subject: Re: Simple Problem....
> >
> >
> >Hi,
> >
> >instead of if(p!=null),
> >
> >use
> >
> >if(!(p.equals(null))
> >{}
> >
> >It will work.
[ ... ]

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]

___________________________________________________________________________
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

Reply via email to