发送HTML表单数据阵列JSP / Servlet的 [英] Sending HTML form data array to JSP/Servlet

查看:142
本文介绍了发送HTML表单数据阵列JSP / Servlet的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从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" />

这样,他们将可以通过<一个href=\"http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getParameterValues%28java.lang.String%29\"><$c$c>HttpServletRequest#getParameterValues().

String[] cars = request.getParameterValues();
// ...

这篇关于发送HTML表单数据阵列JSP / Servlet的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆