问题描述
我从PHP的世界里,有在方括号结尾的名字任何形式的数据自动获取PTED作为数组间$ P $到来。因此,例如:
I am coming from the PHP world, where any form data that has a name ending in square brackets automatically gets interpreted as an array. So for example:
<input type="text" name="car[0]" />
<input type="text" name="car[1]" />
<input type="text" name="car[3]" />
将在PHP端的名称为轿车的一个阵列,3串内被抓。
would be caught on the PHP side as an array of name "car" with 3 strings inside.
现在,有没有什么办法提交给一个JSP / Servlet的后端都在复制这种行为?任何库,可以为你做了吗?
Now, is there any way to duplicate that behavior when submitting to a JSP/Servlet backend at all? Any libraries that can do it for you?
编辑:
要扩大这个问题远一点:
To expand this problem a little further:
在PHP,
<input type="text" name="car[0][name]" />
<input type="text" name="car[0][make]" />
<input type="text" name="car[1][name]" />
会得到我一个嵌套数组。我怎样才能在JSP中重现此?
would get me a nested array. How can I reproduce this in JSP?
推荐答案
在请求参数名称中的 []
标记是为了让PHP认识的必要黑客请求参数为数组。这就是必要其他网络语言,如JSP / Servlet的。摆脱那些括号
The []
notation in the request parameter name is a necessary hack in order to get PHP to recognize the request parameter as an array. This is unnecessary in other web languages like JSP/Servlet. Get rid of those brackets
<input type="text" name="car" />
<input type="text" name="car" />
<input type="text" name="car" />
这样,他们将可以通过<$c$c>HttpServletRequest#getParameterValues()$c$c>.
String[] cars = request.getParameterValues();
// ...
这篇关于发送HTML表单数据阵列JSP / Servlet的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!