Several replies to this thread have suggested code that may crash (i.e.
throw a NullPointerException) if the parameter is not present. Instead of
doing this:

if (request.getParameter("sub").equals("")) ...

which will crash if getParameter() returns null, you should do this:

if ("".equals(request.getParameter("sub")) ...

which will work even if getParameter() does return null.

Hope this helps.

--
Martin Cooper
Tumbleweed Communications


----- Original Message -----
From: "Tony Leake" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 01, 2001 5:41 AM
Subject: Simple newbie question


> Hi,
>
> I'm trying to test a parameter to see if it exists:
>
> on page 1 i have a form with a text field
>
> <input type="text" name="thread">
>
> on page 2 i want to test if the box was filled in and if it contains a
> string or a number. I can't even seem to test if thread is empty.
>
> I've tried
>
> if(request.getParameter("sub")=="")
> {
>   //stuff
> }
> but that doesn't seem to do anything.
>
> thanks for any help
> Tony
>
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to