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

    Join Date
    Jul 2001
    Posts
    8
    Rep Power
    0

    request.getParameter() in same page as form .. ?


    I have a jsp page with a form. form contains a textfield, once the user submits the form, i want jsp scriptlet to get the value of the user input and carry out processing on it within the same page and give a result.

    problem is the first time the page is loaded, there is an error in the request.getParameter() statement since no form has yet been submitted i guess ....

    if i use another page ... it works ... but i want to display the information in the same page ...

    thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    Boston, MA
    Posts
    30
    Rep Power
    56
    You must first check if the parameter exists. I see this mistake even by pros.
    Code:
    String p = request.getParameter("p");
    
    if (p != null) {
        . . .
    }
    
    You can make some external class for processing this, too. Even better if you can define a tag handler to handle that situation. Geary's 'Advanced Java ServerPages' has a pretty good discussion about custom tags.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    Boston, MA
    Posts
    30
    Rep Power
    56
    You must first check if the parameter exists. I see this mistake even by pros.
    Code:
    String p = request.getParameter("p");
    
    if (p != null) {
        . . .
    }
    
    You can make some external class for processing this, too. Even better if you can define a tag handler to handle that situation. Geary's 'Advanced Java ServerPages' has a pretty good discussion about custom tags.

IMN logo majestic logo threadwatch logo seochat tools logo