On Tue, 27 Mar 2001, William Kaufman wrote:
> > 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.
But couldn't they parse the post data as well? I guess it would
require getting the InputStream and parsing it similarly to how the
query string would be parsed (compare parseQueryString and
parsePostData in the old HttpUtils JSDK class). I think this would
have to be done before any calls to getParameter() et al are made
(else it would consume the InputStream). At least, I've seen this
idea mentioned before.
Also, there's the idea of naming the parameters such that the order of
them can be recognized by sorting them in some way.
In any case, any thing along these lines is a bit kludgey, and may not
work in all environments (e.g. browsers), so it would be best to come
up with a design/solution that doesn't require knowing the order of
the parameters.
> > -----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
> >
>
Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]