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方式传递数组参数的更多相关文章

  1. 在ASP.NET MVC中以post方式传递数组参数的示例

    最近在工作中用到了在ASP.NET MVC中以post方式传递数组参数的情况,记录下来,以供参考. 一.准备参数对象 在本例中,我会传递两个数组参数:一个字符串数组,一个自定义对象数组.这个自定义对象 ...

  2. 在ASP.NET MVC中以post方式传递数组参数的示例【转】

    最近在工作中用到了在ASP.NET MVC中以post方式传递数组参数的情况,记录下来,以供参考. 一.准备参数对象 在本例中,我会传递两个数组参数:一个字符串数组,一个自定义对象数组.这个自定义对象 ...

  3. 解决JavaScript中使用$.ajax方式提交数组参数

    一般的,可能有些人在一个参数有多个值的情况下,可能以某个字符分隔的形式传递,比如页面上有多个checkbox: $.ajax{ url:"xxxx", data:{ p: &quo ...

  4. ajax 传递数组参数

    一.ajax 传递数组参数 需要添加: traditional: true, let typeIDArr = [,,,,,]; var that = this; var url = '@Url.Act ...

  5. ajax向后台传递数组参数并将后台响应的数据赋值给一个变量供其它插件使用

    1.在js中封装ajax向后台传递数组参数函数 //combogrid * * @Description 封装ajax向后台传递数组参数并将后台响应的数据赋值给一个变量方便其他插件使用该数据函数 * ...

  6. C#传递数组参数

    在C#中,可以将数组作为参数传递给方法,同时方法可以更改数组元素的值. 一.将一维数组作为参数传递给方法 using System;using System.Collections.Generic;u ...

  7. Restful传递数组参数的两种方式

    第一种,直接传递数组 js直接传递数组 var data = ["123","456"];that.loadDictionarys(data).subscrib ...

  8. js获取get方式传递的参数

    String.prototype.GetValue= function(parm) { var reg = new RegExp("(^|&)"+ parm +" ...

  9. Java SpringMvc+hibernate架构中,调用Oracle中的sp,传递数组参数

    一.问题 我们调用数据,大都是可以直接获取表中的数据,或者用复杂点的sql语句组成的.但是,有时候,当这样达不到我们要的全部数据的时候,这时,我们就用到了存储过程[sp],如果sp需要参数是数组的话, ...

随机推荐

  1. 论文笔记:Fast Neural Architecture Search of Compact Semantic Segmentation Models via Auxiliary Cells

    Fast Neural Architecture Search of Compact Semantic Segmentation Models via Auxiliary Cells 2019-04- ...

  2. 如何在Windows上的Jupyter Notebook中安装和运行PySpark

    When I write PySpark code, I use Jupyter notebook to test my code before submitting a job on the clu ...

  3. 数据库连接超时:“The last packet successfully received from the server was xxx milliseconds ago”

    产生的原因:应用方的数据库连接有效期时间,大于数据库自己设置的有效期. 解决方案: 一.修改druid配置(如果使用druid的话) spring.datasource.druid.validatio ...

  4. java native用法

    说明: native关键字说明其修饰的方法是一个原生态方法,方法对应的实现不是在当前文件,而是在用其他语言(如C和C++)实现的文件中.Java语言本身不能对操作系统底层进行访问和操作,但是可以通过J ...

  5. spring xml配置注入改为手动注入过程

    项目中需要使用MQ组件来接受消息,但是有的时候,在使用的时候,并不能满足spring注入的条件,无法注入.例如 在jfinal的config的afterJFinalStart中,由于jfinal集成s ...

  6. git add * 提示warning: LF will be replaced by CRLF in 解决办法

    在使用git的时候,每次执行 $ git add * 都会提示这样一个警告消息: 虽然说没有什么影响吧. 不过就是觉得太碍眼了, 按照这样设置就没有问题了: git config core.autoc ...

  7. java.lang.ClassNotFoundException: org.apache.log4j.Logger 异常

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'd ...

  8. 从零开始学习Java多线程(二)

    前面已经简单介绍进程和线程,为后续学习做铺垫.本文讨论多线程传参,Java多线程异常处理机制. 1. 多线程的参数传递 在传统开发过程中,我们习惯在调用函数时,将所需的参数传入其中,通过函数内部逻辑处 ...

  9. [解决方法] Java-Class.forName() 反射/映射子类 并转化为父类/接口

    实现通过子类名称字符串 动态获取生成子类. 用于模板方法, 抽象工厂模式等. 代码实现: public TheParentClass getSubClass(String subClassName) ...

  10. EF - Code First 开发方式

    概述: 本节介绍通过 Code First 开发建立新数据库. 借助 Code First 可以选择使用类的特性和属性执行配置,或者使用 XML 配置文件来配置,当然也可以使用 Fluent API ...