在HttpServletRequest.getParameterValues()中对值进行排序 [英] Ordering of values in HttpServletRequest.getParameterValues()

查看:309
本文介绍了在HttpServletRequest.getParameterValues()中对值进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HttpServletRequest.getParameterValues()返回包含给定HTTP请求参数的所有值的 String [] 。有没有人知道这个数组中的值的顺序是否由规范保证与请求中传递这些值的顺序相同?

HttpServletRequest.getParameterValues() returns a String[] containing all values of a given HTTP request parameter. Does anyone know if the order of the values in this array is guaranteed by specification to by the same as the order which those values were passed through in the request?

例如,如果我有GET查询字符串 x = 1& x = 2& x = 3 ,我保证接收 String [] {1,2,3} 当我打电话给 getParameterValues()?它似乎在实践中起作用,但我找不到任何指定必须如此的情况,所以我不愿意依赖它。

For example, if I have the GET query string x=1&x=2&x=3, am I guaranteed to receive the String[] {"1", "2", "3"} when I call getParameterValues()? It seems to work in practice, but I can't find anything which specifies that this must be the case, so I'm reluctant to rely on it.

推荐答案

ServletRequest的javadoc( v2.5 javadoc )没有提及有关该方法的值排序的任何信息。因此,我不会依赖于保留的订单。

The javadoc for ServletRequest (v2.5 javadoc) does not mention anything about the ordering of values for that method. As such, I wouldn't rely on the order being preserved.

更新:还检查了2.5的规格文档,包含有关getParameterValues()的以下信息。它没有提到关于查询字符串的排序,所以我认为你看到的行为是实现细节,没有被定义为接口的一部分。

Update: also checked the spec document for 2.5, contains the following information relating to getParameterValues(). It does not mention anything about ordering with respect to the query string, so I think the behaviour you are seeing is implementation detail, not defined as part of the interface.


参数存储为一组
名称 - 值对。对于任何给定的
参数名称,可以存在多个参数
值。以下方法ServletRequest接口的

可用于访问参数:

The parameters are stored as a set of name-value pairs. Multiple parameter values can exist for any given parameter name. The following methods of the ServletRequest interface are available to access parameters:




  • getParameter

  • getParameterNames

  • getParameterValues

  • getParameterMap

    • getParameter
    • getParameterNames
    • getParameterValues
    • getParameterMap


    • getParameterValues方法返回一个
      的String对象数组,其中包含与$ b $关联的所有
      参数值b参数名称。从getParameter方法返回的
      值必须是

      getParameterValues返回的String
      对象数组中的第一个值。
      getParameterMap方法返回
      请求参数的
      java.util.Map,其中包含名称为键
      和参数值作为映射值。

      The getParameterValues method returns an array of String objects containing all the parameter values associated with a parameter name. The value returned from the getParameter method must be the first value in the array of String objects returned by getParameterValues. The getParameterMap method returns a java.util.Map of the parameter of the request, which contains names as keys and parameter values as map values.

      为了将来参考,Java Servlet规范可以从 Sun,我的意思是Oracle的网站。您可以仔细检查您感兴趣的特定servlet版本。

      For future reference, the Java Servlet specs can be downloaded from Sun, I mean Oracle's website. You can double check the specific servlet version you're interested in there.

      这篇关于在HttpServletRequest.getParameterValues()中对值进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆