Submitting HTML form dataset to JSP / Servlet

I come from the world of PHP, where any form data that has a name ending with square brackets is automatically interpreted as an array. For example:

<input type="text" name="car[0]" /> <input type="text" name="car[1]" /> <input type="text" name="car[3]" /> 

will be caught on the PHP side as an array of the name "car" with 3 lines inside.

Now, is there a way to duplicate this behavior when sending to the JSP / Servlet server at all? Any libraries that can do this for you?

EDIT:

To expand this problem a little further:

In PHP,

 <input type="text" name="car[0][name]" /> <input type="text" name="car[0][make]" /> <input type="text" name="car[1][name]" /> 

will give me a nested array. How can I reproduce this in JSP?

+8
arrays html jsp forms servlets
source share
1 answer

The designation [] in the name of the query parameter is a necessary hack to force PHP to recognize the query parameter as an array. This is not required in other web languages ​​such as JSP / Servlet. Get rid of these brackets

 <input type="text" name="car" /> <input type="text" name="car" /> <input type="text" name="car" /> 

This way they will be available to HttpServletRequest#getParameterValues() .

 String[] cars = request.getParameterValues(); // ... 
+9
source share

All Articles