zoukankan      html  css  js  c++  java
  • 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]
  • 相关阅读:
    Windows 7 SP1无人值守自动应答文件制作
    Ubuntu GNOME单击任务栏图标最小化设置
    NOIP2017题解
    NOIP2017游记
    大模拟1.0
    奇袭
    礼物
    找硬币
    Fiolki
    SQLserver Delete from where 与Oracle delete from where 的差异
  • 原文地址:https://www.cnblogs.com/caihemm/p/9206957.html
Copyright © 2011-2022 走看看