On Wed, 4 Apr 2001, Poornima Visvesvaran wrote:
> Hi,
>
> instead of if(p!=null),
>
> use
>
> if(!(p.equals(null))
> {}
>
> It will work.
No it won't. First of all, syntactically, in the code
if(!(p.equals(null))
null is an identifier (i.e. a variable name), and I believe null is a
reserved keyword and hence can't be used as an identifier. So this
probably won't even compile. And semantically/logically, you need to
check whether p is null before you try to use/access it (i.e. as
calling a method on it does). The proper way to do this -- assuming
you want to check whether p is non-null and non-empty -- is:
if (p != null && ! p.equals(""))
or alternatively:
if (p != null && p.length() > 0)
[ ... ]
> > > -----Original Message-----
> > > From: irene_plj asiamail.com
> > [SMTP:[EMAIL PROTECTED]]
> > > Sent: Wednesday, April 04, 2001 10:57 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: Simple Problem....
> > >
> > > Hi all ,
> > >
> > > The problem wf the below code(part of my
> > servlet)is i always get the "if"
> > > condition even if it "p" equals null..
> > > Wat could be wrong???
> > > This is such a simple problem but i jus cannot get
> > the "else" condition
> > > when p==null.
> > > Anyone any idea why this cannot work??
> > > Thks .
> > >
> > > ******************************************
> > > ..
> > > ..
> > > try
> > > {
> > > String p=request.getParameter("ID");
> > > if(p != null)
> > > {
> > > String to=p+"@asiamail.com";
> > > }
> > > else
> > > {
> > > String to="[EMAIL PROTECTED]";
> > > }
> > >
> > > }
> > > ..
> > > ..
> > > **********************************************
[ ... ]
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