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 (), then you can just send them as multipleparameters 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 [] inorder 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\"]; // value1echo 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 theexact parameter name including the braces.
String[] foo = request.getParameterValues(\"foo[]\"); // [value1, value2, value3]
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务