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]
  • 相关阅读:
    Vsftp的PASV mode(被动模式传送)和Port模式及 Linux下VsFTP配置全方案
    vsftpd:500 OOPS: vsftpd: refusing to run with writable root inside chroot ()错误的解决方法
    CentOS7.2部署FTP
    Apache与Nginx的优缺点比较
    MySQL存储引擎--MyISAM与InnoDB区别
    CentOS 7下搭建配置SVN服务器
    Remi 安装源
    tmpx75 I2C 温度传感器驱动程序添加
    QT 5.7.0 交叉编译记录
    am335x SGX 移植
  • 原文地址:https://www.cnblogs.com/caihemm/p/9206957.html
Copyright © 2011-2022 走看看