Ok, let's say we have a form submission where each text box is a line of an e-mail.

What sense does it make to retrieve an Address before a Name?

The way I fixed the problem was to use getParameterNames and to make
each name Comparable in the order I needed.

<input name="1_Name" . . .>
<input name="2_Address" . . .>


Then I used a TreeMap after I retrieved
all the values to put them back in the order that they were in on the HTML page.
In this case it was very annoying to me that getParameterName didn't give me the
form elements in the order that they were in on the HTML page.  Not that big of a
deal though -- putting them back in order was an easy exercise.

James



-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Kevin
Mukhar
Sent: Tuesday, October 17, 2000 4:36 PM
To: [EMAIL PROTECTED]
Subject: Re: [SERVLET-INTEREST] Order of post data


But the question is still, why does it matter what the order of the form
elements is? It doesn't matter where an element appears in the form,
getParameterValues will always work. You can call getParameterValues in
any order.

For example, given a form:
<form>
<input name=bla1 .../>
<input name=bla2 .../>
<input name=bla3 .../>
</form>

Your servlet code can be
String[] s1 = getParameterValues("bla1");
String[] s2 = getParameterValues("bla2");
String[] s3 = getParameterValues("bla3");

or it could be
String[] s1 = getParameterValues("bla3");
String[] s2 = getParameterValues("bla1");
String[] s3 = getParameterValues("bla2");

or it could be
String[] s1 = getParameterValues("bla2");
String[] s2 = getParameterValues("bla3");
String[] s3 = getParameterValues("bla1");

It just doesn't matter.

And if you have forms where the same name is used multiple times, you
should be using getParameterValues() and not getParameter(). Knowing the
order won't help you because getParameter() will always return the same
item. getParameter() where the name was used multiple times in the form
is the same as calling getParameterValues() and retrieving the first
element in the String array (in other words, getParameter =
getParameterValues()[0]).

Besides, can't you just look at the form to see what order they are in?

K Mukhar

Tiago Antão wrote:
>
> On Tue, 17 Oct 2000, SEYNAVE, PATRICK wrote:
>
> > I'm not sure I understand your problem... I read post data by calling
> > request.getParameter("param_name") for each one of my parameters.
> > It's that easy!
>
> the problem is this, if I have a form
> <input name=bla1 .../>
> <input name=bla2 .../>
> <input name=bla3 .../>
>
> I'd like to know that the order specified in html was
> first - bla1,
> 2     - bla2,
> 3     - bla3
>
> More, if I have input names that are equal I'd need to know the order (And
> yes, I have users who request to repeat form paramater names in their
> forms, go figure...)

___________________________________________________________________________
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