Hi,

thanks for the detailed answer.

The reason why I used the brackets was that in some cases (browsers) only
the first value was returned. (Even if there were more then one hidden
field with that name)

Also mentioned here: http://stackoverflow.com/a/6547234 - PHP is also
resolving the variable without brackets.

There are various other questions at stackoverflow mentioning to get the
variable without brackets:

http://stackoverflow.com/questions/6547209/passing-array-using-html-form-hidden-element
http://stackoverflow.com/questions/4237090/how-to-pass-array-through-hidden-field
http://stackoverflow.com/questions/29076219/javascript-storing-array-of-objects-in-hidden-field

Don't know if this should be supported.

kind regards

Tobias

2017-05-03 12:05 GMT+02:00 André Warnier (tomcat) <a...@ice-sa.com>:

> On 03.05.2017 11:23, Tobias Soloschenko wrote:
>
>> Hello everyone,
>>
>> I just updated to tomcat 8.0.43 and I noticed a special behavior I want to
>> discuss. (I don't know if this only occurs with this version)
>>
>> When I add two hidden fields within a form like:
>>
>> <input type="hidden" name="array[]" value="1" />
>>
>> <input type="hidden" name="array[]" value="2" />
>>
>>
>> I just thought to access the parameter values within the java api like
>>
>> String[] myArray = httpServletRequest.getParameterValues("array");
>>
>>
>> In my case however I just can access them like (with brackets):
>>
>> String[] myArray = httpServletRequest.getParameterValues("array[]");
>>
>>
>> This also applies to httpServletRequest.getParameterMap().containsKey
>>
>>
>> Is this an expected behavior?
>>
>>
>>
> I would tend to say : yes, it is expected.
> (This also has nothing to do with tomcat per se, and is more of the domain
> of the HTML and HTTP specifications).
>
> I have not checked the relevant HTML/HTTP specs to verify which characters
> precisely are allowed in the "name" attribute of a HTML <form> field.
> But assuming that "[" and "]" /are/ allowed in such attributes, then that
> is the name under which the value of this parameter will be sent by the
> browser to the server.
>
> More precisely : if you have in your form an <input> element such as :
>
> <input type="hidden" name="xyz[123abc]" value="1" />
>
> (whatever "xyz[123abc]" may be, in terms of valid characters)
> then "xyz[123abc]" is the name/label of this parameter, and the browser
> will send the corresponding input field value to the server as something
> like :
>
> xyz[123abc]=1
>
> The fact that this label /resembles/ the way in which you would invoke an
> array in Java (or any other server-side programming language) is pure
> coincidence.
>
> In other words again, in your above example, if you replaced "array[]" by
> "array][" (or "array)(", or "array(xyz)" or "variable#1") everywhere, it
> would work just the same. It's just a label.
>
> And the fact that in your example they are seen as an array on the java
> side, is just because there is more than one value sent by the browser with
> that same label, and the POST parsing logic on the server side then makes
> this into an array of values.
>
> This all being said, I would not name any input fields in a form with a
> name like "array[]". That is bound to create confusion, as you yourself can
> now attest.
> You can name is "ferrari" instead; but that does not mean that on the
> server side, you should expect something red with 4 wheels and 12 cylinders.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

Reply via email to