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


    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]
  • 相关阅读:
    node vue 项目部署问题汇总
    Java删除空字符:Java8 & Java11
    moco固定QPS接口升级补偿机制
    Selenium4 IDE特性:无代码趋势和SIDE Runner
    JsonPath工具类单元测试
    Mac上测试Internet Explorer的N种方法
    JsonPath工具类封装
    Selenium4 IDE,它终于来了
    质量保障的方法和实践
    JsonPath实践(六)
  • 原文地址:https://www.cnblogs.com/caihemm/p/9206957.html
Copyright © 2020-2023  润新知