> Please correct me if I am wrong. And if the webbrowser gives the
> form fields in correct sequence, then this Enumeration should
> also get them in sequence, which results that you get the
> correct sequence of attribute names.

But getParameterNames() returns an enumeration on a java.util.Hashtable's
keys[*], so you'll get them in some hashcode-like order, not the order
they're returned in the HTTP POST, whether or not the values were put into
that Hashtable in that order.

([*]...in the Tomcat implementation.  The JSDK spec doesn't say what the
underlying implementation is--you could get the names in any order at all.)

In short, there's no real way to get the order of the parameters other than
getting the whole string (e.g., with HttpServletRequest.getQueryString())
and parsing it up yourself.

And even this won't work for the original request: he's doing a POST, not a
GET, and he wants the parameters in the order they appear in a stream which
has already been consumed.

                                                            -- Bill K.


> -----Original Message-----
> From: Frans Verhoef [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, March 27, 2001 5:27 PM
> To: [EMAIL PROTECTED]
> Subject: Re: How to get request prameters in right order.
> 
> 
> 
> > I can get all parameters by the help
> request.getParameterNames() but
> >  it returns them as hash table keys. So we lost their original
> order.
> 
> Actually, request.getParameterNames() returns an Enumeration,
> instead of a Hash table. So you should be able to run through
> this Enumeration with (String)yourEnumeration.nextElement();
> 
> Please correct me if I am wrong. And if the webbrowser gives the
> form fields in correct sequence, then this Enumeration should
> also get them in sequence, which results that you get the
> correct sequence of attribute names. As a result you get get the
> real values of the parameter in sequence with:
> 
> Enumeration yourEnumeration = request.getParameterNames();
> while (yourEnumeration.hasMoreElements())
>    /*do something funny with */
> request.getParameter((String)yourEnumeration.nextElement())
> 
> Hope this helps.
> Cheers
> Frans
> 
> ________________________________________________
> Get your own "800" number
> Voicemail, fax, email, and a lot more
> http://www.ureach.com/reg/tag
> 

Reply via email to