#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    3
    Rep Power
    0

    JSP Text box never = Null


    I am trying to use if statements with a text box. I set up a text box, with name submit.

    I then post the box to another page and use request.getparameter to get the value of the box.

    This is fine as long as the box has a value.

    When I don't fill in the box and submit it - I don't get a value of null.

    This mean that I can't use my if statements i.e. if(submit == null)
    as the request.getParameter is never = null.

    This shouldn't be too hard.
  2. #2
  3. No Profile Picture
    hmmmm...
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    UK
    Posts
    37
    Rep Power
    14
    just do an extra check

    String submit = request.getParameter("submit");

    if (submit == null || submit.equalsIgnoreCase("null")) {

    }
    Some things can be more simple than you think....
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    3
    Rep Power
    0

    no joy


    I've tried that now: but to no success.

    Heres the form:
    <form action = "testa.jsp" method="post">
    <input type="text" name="username" size="25">
    <br>



    <input type="submit" value="Submit">

    Heres the result page:

    <%
    String submit = request.getParameter("username");
    out.write(submit);
    if (submit == null || submit.equalsIgnoreCase("null")) {
    out.println("good");
    }
    else{
    out.println("bad");
    }

    %>

    I can't get it to say "good"
  6. #4
  7. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    try submit.equalsIgnoreCase("")
    -james
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    3
    Rep Power
    0
    THANK YOU MATE!!!!

    YOU ARE THE MAN.

    It works, nice one.

    Mark

IMN logo majestic logo threadwatch logo seochat tools logo