DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2002
    Posts
    4

    Unhappy Checking if variable is null

    Hi All

    I have this code

    var1 = request.getParameter("id");

    but sometimes there is no "id" (and thatīs ok), but it returns "null".

    How do I check if var1 is null ?

    if var1 == null donīt work

    thankx
    JoPi

  2. #2
    Join Date
    Mar 2003
    Posts
    84
    use code blocks and actually paste in what you have, I don't know how to help you.
    I'm surprised more of you people don't get hit by cars.

  3. #3
    Join Date
    Mar 2003
    Posts
    32
    What you have to do is use the compareTo function. It will compare the text that is stored in a string to a different value. This is how to check if it has nothing in it:

    if (var1.compareTo("") == 0) {
    //Var1 is null
    }

    Hope this helps, if you have any more questions just post.
    - Master Of Souls
    "Weeks of coding can save hours of planning."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links