This has recently been discussed and answered.

The paramaters are returned in no particular order.  Therefore, you need to
name your form elements with an order identifier.  For instance, name your
items 1_ITEM, 2_ITEM, 3_ITEM.  These will be returned in the enumeration
something like 2_ITEM, 1_ITEM, 3_ITEM, so you will need to order them.
James Wilson suggested using a TreeMap, which I also recommend as it works
well.  Read each form name from the enumeration, then add it to the treemap
with the order number as the key.  This will sort your list of parameter
names in the map as you insert them.  You can then pull them out with ease
in order.

Here's an example given by James:

Map map = new TreeMap();
Enumeration e = request.getParameterNames();

while(e.hasMoreElements())
{

        String tempString = e.nextElement().toString();
        String tempInt = < position of "_" in tempString >
        String tempKey = < everything to the left of the "_" in tempString >
        String tempValue = < everything to the right of the "_" in
tempString >

        map.put(new Integer(tempKey), tempValue);
}

Collection tempCollection = map.values();
Iterator tempIterator = tempCollection.iterator();

while(tempIterator.hasNext())
{
        System.out.println(tempIterator.next());
}

-Mark

-----Original Message-----
From: Jason Reynolds [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 23, 2001 2:24 PM
To: [EMAIL PROTECTED]
Subject: Order of Form Names


Using Enumeration e = request.getParameterNames Is there any way to grab
the paramNames from an html form in the order in which they appeared on
that form.  OR, what is the method in which getParameterNames grabs
parameters from a form.  I have found no set pattern in which it grabs form
parameters.

Example HTML form:
<form action="FooServlet">
<input type="checkbox" name="ITEM_3" value="A"> ITEM3
<input type="checkbox" name="ITEM_1" value="B"> ITEM1
<input type="checkbox" name="ITEM_2" value="C"> ITEM2
</form>

Servlet snippet:
Enumeration foo = request.getParameterNames();
while (foo.hasMoreElements()) {
        htmlout.println(ParamName)
        htmlout.println(ParamValue)
}

Output:
ITEM_2 equals C
ITEM_3 equals A
ITEM_1 equals B

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to