• Post Reply Bookmark Topic Watch Topic
  • New Topic

Submission Parameter Order Maintained?  RSS feed

 
Reginald Blank
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anything in the HTML specification about whether submitted GET or POST parameters must retain their order?
E.g. In the following is there anything in the spec that says the following data should be returned in the order they appear in the HTML code. And, most importantly, is there anything that says the firstName and surname fields should actually match up with each other, i.e. the order can change but in the same way for each field?



 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am fairly certain that either 1) the spec says nothing about that, or 2) if it does say something, it's that the order is not retained.

The usual approach is to make field names unique, maybe by adding an index like "surname_1".
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36441
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Ulf; I spent a few minutes looking and couldn't find anything in the spec either. And even if there was, I'd be afraid of an app server not following it.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no order guarantee.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I recall, the implementation of the HttpServletRequest that Tomcat uses keeps the parameter names/values in a hashtable, and hashtables are unordered collections.

If you were to grab the original URL text and parse it manually, of course, then you'd be able to dissect the URL according to whatever text-processing rules you desired, but that would mean a lot of extra coding.

As for the URL itself, I don't know offhand if the RFC's mandate that name/value pairs MUST be transmitted by the client in the natural order that they were defined in on the form, but I suspect that most GET processors do and probably all POST processors do. It's still not something I'd want to make part of critical design decisions without formal assurances, though.

In the case of multiple values under the same name, I am fairly certain that the returned value array will, in fact, be in the natural order of the form, and yes, specifically, that would mean that firstName[1] would pair with surname[1], assuming that there was a 1-1 correspondence between input definitions. That would be equally true regardless of whether you laid them out as firstname/surname/firstname/surname or firstname/firstname/surname/surname, since the only guranteed ordering is within the name, not between names.

Again, this is assumptions based on reasonableness and experience. Check the RFC that specifically defines HTTP FORM POST operations for specifics before spending a lot of time, effort, and money.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!