Adam Gent
Adam Gent

Reputation: 49095

Request Parameter order in Servlet Containers

Apparently the order of request parameters is not preserved in the Tomcat servlet container (per google it seems other containers share the same problem).

This seems very wrong.

How would one restore the actual order of request parameters from a HttpServletRequest?

EDIT BTW for those that think order for request parameters does not matter there is a difference between:

http://blah?a=1&a=2

and

http://blah?a=2&a=1

So order does matter for duplicate request parameters (luckily Java does handle this right).

Upvotes: 1

Views: 2898

Answers (2)

Dave
Dave

Reputation: 6179

You likely could use the getRequestURL: http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getRequestURL() and from there parse out the parameters.

BUT, in reply to your comment "This seems very wrong.", I think you should rethink your stance.

Ordering your parameters simply doesn't make sense. Lets say - for example - you were asking for a list of cars based on parameters. It shouldn't matter if you're asking for a list of fords that are green or a list of green cars that are fords.

Upvotes: 0

Bozho
Bozho

Reputation: 597324

Normally you should not depend on the order of parameters. If you are really sure this is necessary, you can:

  • use request.getQueryString() to see GET parameters
  • get the raw request (request.getInputStream()) and read the submitted POST params.

Upvotes: 3

Related Questions