On Mon, 24 Jan 2000, John McDonald wrote:

> Actually is should be:
>
> if(null == temp || temp.length() == 0)
>
> Then you won't get a nullPointerException if it IS null. capice?

Ugh, we just went through this about a hundred times.  In summary:
THERE IS ABSOLUTELY NOTHING WRONG WITH:

if (temp == null) {
  ...
}

or

if (temp == null || temp.length() == 0) {
  ...
}

NOTHING!  YOU DO NOT RISK GETTING A NullPointerException THIS WAY.
YOU DO NOT NEED TO FLIP THE ORDER OF THE temp/null AROUND THE "==".
CAPICE?!

Sorry for shouting.


> ----- Original Message -----
> From: Floyd Marinescu <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, January 24, 2000 7:53 AM
> Subject: Re: Absolute frustration
>
>
> > >If the radio wasn't checked at all the first line of output will be
> > >null, but if I test against that I get a NullPointerException.  If I
> > >use:
> >
> >   You shouldn't get a null pointer exception if you are testing
> > properly: The way you would normally test to see if its null
> > (hasn't been checked) is:
> > String temp = req.getParameter("radio1");
> > if(temp == null)
> > {
> >      file://do something
> > }
> >
> >
> > >out.println(req.getParameterValues("radio1"));
> > >I get something like:
> > >[Ljava.lang.String;@7310a09a
> >   This is because getParameters always returns a string[]. Even an
> > empty array, but it won't return you a null. You can check this
> > one like this:
> > String[] s = req.getParameterValues("radio1");
> > if (s.length == 0)
> >    file://do something
> >
> >
> > >I don't need the memory address, I need the string in the memory
> > >address.
> >     Hahaha, this is Java my friend, no need to worry about memory
> > addresses.
> >
> >
> > >Thanks for ANY help given.
> >   Ok, here is the proper way to validate radio/check buttons. In
> > your html, give each radio button the same name (ie: not radio1,
> > 2, 3, but just radio for all of them).
> >     In your servlet you do a req.getParameterValues, and then
> > iterate through the returned array to get the data you want.
> >
> >    Hope this helps.
> >
> > Floyd
> >
>

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