发送HTML表单数据阵列JSP / Servlet的

编程入门 行业动态 更新时间:2024-10-10 23:21:35
本文介绍了发送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" />

这样,他们将可以通过HttpServletRequest#getParameterValues().

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

更多推荐

发送HTML表单数据阵列JSP / Servlet的

本文发布于:2023-10-12 05:08:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483800.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阵列   表单   数据   HTML   JSP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!