www.webdeveloper.com
Results 1 to 2 of 2

Thread: JSP and Forms: if a field is empty

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    27

    JSP and Forms: if a field is empty

    Hi. I have the following code that gets the input names and their values from a form that is to be sent to my email. This is working fine.

    Code:
      Enumeration paramNames = request.getParameterNames();
         while(paramNames.hasMoreElements()) {
           String paramName = (String) paramNames.nextElement();
           String paramValue = request.getParameter(paramName);
           message.println(paramName + ": " + paramValue);
           
          }
    Then, when submitting the form, I want to leave out the fields that are empty, so I added an IF statement to the above:

    Code:
      Enumeration paramNames = request.getParameterNames();
         while(paramNames.hasMoreElements()) {
           String paramName = (String) paramNames.nextElement();
           String paramValue = request.getParameter(paramName);
           if (paramValue != null) {
           message.println(paramName + ": " + paramValue);
    }
           
          }
    But the IF loop doesn't work and don't know why. I appreciate if anyone could help me with this.

    Thanks in advance
    Atrisa

  2. #2
    Join Date
    Oct 2012
    Posts
    27
    Go it.

    Code:
    if (request.getParameter(paramName) != null && 
                   request.getParameter(paramName) != "") {
           message.println(paramName + ": " + paramValue);
           }
    One thing though: after this, the email goes to the spam folder rather then my inbox. I guess it is because I am testing and sending so many emails frequently and could be some security settings. When I try a new sender email then it goes to my inbox. Anyway, if any of you has a better explanation, please share it with me.
    Last edited by Atrisa Milani; 10-15-2012 at 06:52 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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



Recent Articles