www.webdeveloper.com
Results 1 to 5 of 5

Thread: JSP: deliver form fileds in the same order as they are in the HTML form

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    29

    JSP: deliver form fileds in the same order as they are in the HTML form

    The following script delivers the form data to my email, but not in the same order as the fields are in the fom. e.g. Name, Email and Comment fields come respectively in the form, but when delivered to my email, each time they are sorted in a different way.
    Code:
    Enumeration paramNames = request.getParameterNames();
         while(paramNames.hasMoreElements()) {
           String paramName = (String) paramNames.nextElement();
           String paramValue = request.getParameter(paramName);
           
           if (request.getParameter(paramName) != null && 
                   request.getParameter(paramName) != "") {
           message.println(paramName + ": " + paramValue);
           }
          }
    I know I could control that using a HTML structure in my JSP page, but is there any other way to address this problem with JSP in the above code?

  2. #2
    Join Date
    Jan 2009
    Posts
    3,346
    Without specifying an order you'll get them in the order they were received using the above code.

  3. #3
    Join Date
    Oct 2012
    Posts
    29
    Actually I haven't specified any order for the form field submission; it is just like what I have done it in the above code, but still get the data to my email in different sequences each time. "The order in which getParameterNames() returns parameters can be different than the order in which they appear in the HTML form". Looks like I need to use a Collection e.g. ArrayList in order to keep the right order, as read while googling. But since this my first ever JSP code, since graduation, this doesn't come as an easy thing for me I will keep fighting!
    Last edited by Atrisa Milani; 10-18-2012 at 02:31 AM.

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    Have you tried setting a tabindex to the fields in the html to see if that helps it be more consistent?

  5. #5
    Join Date
    Oct 2012
    Posts
    29
    Yep, tried that but didn't help. Thanks anyway.

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