On Mon, 17 Apr 2000, blueads.com wrote:
> Hi Stephen,
>
> I noted there is not a space between the pQ2="", so maybe put pQ2="
> " or pQ2=' ' where a single quotation mark denotes a char space. The
> difference between == and .equals() should not matter since you are
> working with a String A.K.A. an Object.
I hate to respond to such an off-topic post, but this response has
some serious misinformation. There is a *huge* difference between ==
and .equals(), and that in fact is causing the problem here, as a
couple of other posters have pointed out. Basically, using .equals()
accesses a method of an object, and if that object is null, voila,
NullPointerException. You want to check if it is == null, i.e. if it
doesn't refer to anything.
There is a bit of confusion added here by the fact that a null String
object prints out as "null" (no strings), which I'm not sure was the
greatest decision in the world.
> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
> Lambert, Stephen : CO IR
> Sent: Monday, April 17, 2000 5:40 PM
> To: [EMAIL PROTECTED]
> Subject: checking for null in a doPost method
>
>
> I'm trying to pass blanks for a null into my db from an html form.
> Code as follows:
>
> String pQ2 = request.getParameter("check2");
> if (pQ2.equals("null") {pQ2="";
> }
>
> I end up with the error "java.lang.NullPointerException".
> Even though when I display the variable pQ2, it gives me "null"(no quotes)
> using:
>
> out.println(pQ2);
>
> Anybody know how to check for null data from a doPost method?
> Thanks,
> Stephen.
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