码迷,mamicode.com
首页 > 编程语言 > 详细

URL 通过Get方式传递数组参数

时间:2018-06-21 11:48:28      阅读:2262      评论:0      收藏:0      [点我收藏+]

标签:trigger   key   后台   一个   print   order   需要   AC   解析   

URL 通过Get方式传递数组参数

方法1:

?id=1&id=2&id=3

后台获取时,只需要reqeust.getParameterValues("id") 获取String数组。

 

 

http协议的要求

解析参数时,相同的key会覆盖前一个,
如果带[]会当成一维数组来处理,就不会覆盖了

 

直接可以url =url+"?str1="+arrayP[0]+"&str2="+arrayP[1];

 

 

Generally, when the target server uses a strong typed programming language like Java (Servlet), then you can just send them as multiple parameters with the same name. The API usually offers a dedicated method to obtain multiple parameter values as an array.

foo=value1&foo=value2&foo=value3
String[] foo = request.getParameterValues("foo"); // [value1, value2, value3]

The request.getParameter("foo") will also work on it, but it‘ll return only the first value.

String foo = request.getParameter("foo"); // value1

And, when the target server uses a weak typed language like PHP or RoR, then you need to suffix the parameter name with braces [] in order to trigger the language to return an array of values instead of a single value.

foo[]=value1&foo[]=value2&foo[]=value3
$foo = $_GET["foo"]; // [value1, value2, value3]
echo is_array($foo); // true

In case you still use foo=value1&foo=value2&foo=value3, then it‘ll return only the first value.

$foo = $_GET["foo"]; // value1
echo is_array($foo); // false

Do note that when you send foo[]=value1&foo[]=value2&foo[]=value3 to a Java Servlet, then you can still obtain them, but you‘d need to use the exact parameter name including the braces.

String[] foo = request.getParameterValues("foo[]"); // [value1, value2, value3]

URL 通过Get方式传递数组参数

标签:trigger   key   后台   一个   print   order   需要   AC   解析   

原文地址:https://www.cnblogs.com/caihemm/p/9206957.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!