ср, 17 февр. 2021 г. в 12:09, Mark Thomas <ma...@apache.org>: > > On 16/02/2021 14:58, Christopher Schultz wrote: > > All, > > > > I'm sorry for using users@ as my own personal Google but I'm sure > > someone knows this off the top of their head and can save me a lot of > > reading. > > > > I'm wondering about which specs mention how to handle URL parameters > > (and POST parameters, for that matter) in terms of ordering. For > > example, if I have a URL like: > > > > https://example.com/context/resource?a=1&b=2&c=3&a=6 > > > > (Note that I have "a" in there twice) > > > > If I call request.getParameterNames(), is there a predictable order in > > which those parameters will be handed back? I'd love to hear that not > > only are they returned in "URL order" (that is, the left-most parameter > > is the first returned in that enumeration) in Tomcat, but either the > > servlet spec, the CGI spec, or some other spec dictates that order > > explicitly. > > Yes, they will be in that order. (See ApplicationHttpRequest.parameters, > ParameterMap.delgatedMap and LinkedHashMap > > The order isn't explicitly defined in any specification I am aware of. > However, the Servlet spec does state (3.1) that query string parameters > should be presented before parameters parsed form the request body.
1. When there are multiple values, the order of values is preserved. Java Servlet 4.0 spec has an example in its text that shows how the order of values is preserved (chapter 3.1 "HTTP Protocol Parameters"): <quote>Data from the query string and the post body are aggregated into the request parameter set. Query string data is presented before post body data. For example, if a request is made with a query string of a=hello and a post body of a=goodbye&a=world, the resulting parameter set would be ordered a=(hello, goodbye, world)</quote> 2. Original specification for url-encoded parameters is not HTTP, but HTML specification. The place where I first saw it many years ago was here: https://tools.ietf.org/html/rfc1866#section-8.2.1 HTML 2.0 spec > The fields are listed in the order they appear in the document Personally, I would not rely on the order of names provided by getParameterNames(), as it would be surprising for a client if processing of a request depends on the order of parameter names. In the same way as whether reordering of input fields on a web form could break its processing. Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org