Re: Access hidden fields array
Hi, thanks a lot for the clarification. I changed the implementation to access the parameter with brackets, now. Everything is working like expected. kind regards Tobias - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Access hidden fields array
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Tobias, On 5/3/17 6:48 AM, Tobias Soloschenko wrote: > 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) This is incorrect. Browsers don't have a high-level API for manipulating URLs, parameters, etc. If you are using a toolkit, it may add these restrictions, but the browser has nothing to do with it. > Also mentioned here: http://stackoverflow.com/a/6547234 - PHP is > also resolving the variable without brackets. PHP uses the "[]" suffix to indicate that a parameter name is expected to have multiple values, and expose those values to the PHP script as an array (instead of returning e.g. only the first value encountered). > There are various other questions at stackoverflow mentioning to > get the variable without brackets: > > http://stackoverflow.com/questions/6547209/passing-array-using-html-fo rm-hidden-element > > http://stackoverflow.com/questions/4237090/how-to-pass-array-through-hid den-field > http://stackoverflow.com/questions/29076219/javascript-storing-array-o f-objects-in-hidden-field > > Don't know if this should be supported. The servlet spec is clear: the name of the parameter is the name of the parameter from the HTTP request. If you decide to name your parameter "array[]", then you must access it using "array[]". If you want to use a framework that adds that kind of interpretation, you are welcome to do so, but Tomcat will never add anything like that. - -chris -BEGIN PGP SIGNATURE- Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJZCeZ+AAoJEBzwKT+lPKRYo3YP+gPNiJbe0zeTrowUnsKxiViI 0dBZqQwm4XLqxVPNobixQQ1Su0uKSfBCesQwrdhVZCBRGKb8DO5UvSxvWUexr84I GFfNObXiZD9b0pf9JRGNjlrBT4EA8/ehWGCqgVT1cqUfme2GtPp5Km9ODjqzwhKO XKhXSuBhO1weg948hNd0W1nrYfWd632FoWiLXVbiXERlsD4s5eTakgrkQkaf9NA0 meEbOFqvvNinU73Z2rLql0S3s4dW7UVlUNKqRK+yaWEM73RE8Ij985uXQAuiPOYz LNdauOkFo9SshpEmAOGGN/TVCowqGKhkEcVL2Jo49oU0lGxyJJGkgtOrQwnWQsHy 3iJhVvV2AWTwN5ICevZ183oNSYDFALisIExuQmMoCg6aKIhHl4l9KccC+DMgpmZp kAiGqJAIHzJOFcxXuP8gVuefmPJn4pfTA9ZN2yEFbWAwJm8IB6osadjfUTLwAdHz dTBn1BtkcoB+cC3eiHmOnpigtkbHb7/j9Oeud3tCCuyvyA8ykKzPm4glkTq+heN4 yNvsGdBGthG7IdVHDaOptm8TGoWf9Q6r9k/jpkyl3DYInFm8D1m+UWJpSpaFwL+d vHaZUAJTw/F1UQaoFCIShPca7ncNjNy/P3EERw07unHdynVtwGzDr3eKqBn73ehA 2cl2EUS9mgegSz/0/U2V =H+SQ -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Access hidden fields array
Hi again. First, on this list please do not top-post. See : http://tomcat.apache.org/lists.html#tomcat-users Important --> 6 I have reformated your message according to that. > 2017-05-03 12:05 GMT+02:00 André Warnier (tomcat): 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: 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 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 element such as : (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. On 03.05.2017 12:48, Tobias Soloschenko wrote: 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. There is something confusing in your posts so far. This is a Tomcat user's list. Tomcat is a Java Servlet Engine, written in Java. Your example above also seemed to be Java. But the links you propose above all relate to PHP applications, and they are a bit confusing (and sometimes also confused) themselves. I mean, there is some information in them that may be relevant to your issue, but also a lot of noise that is irrelevant here. There are 3 parts to your issue : 1) how the HTML form is generated, before it is sent to the browser 2) once it is "in" the browser, what the looks like (in terms of input fields and values), and how its content will be sent to the server when the user presses the submit button 3) the application, on the server side, which will parse this POST content, and how the data will look to it Only (3) is really relevant on this list. And as far as that is concerned : A) if your contains 3 input elements like then what the browser sends to the server (in one way or another), will look like f1=1 f1=2 f1=3 and, in a Java application on the server, to get these values you would use something like : String[] myArray = httpServletRequest.getParameterValues("f1"); and in myArray, you would get [ "1", "2", "3" ] and this is true whatever the name "f1" would be replaced by, in the as well as in the Java code. B) if your contains 3 input elements like then what the browser sends to the server (in one way or another), will look like f1=1 f2=2 f3=3 then, in the Java application on the server, if you use something like : String[] myArray =
Re: Access hidden fields array
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): > 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: >> >> >> >> >> >> >> 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 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 element such as : > > > > (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 > >
Re: Access hidden fields array
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: 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 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 element such as : (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
Access hidden fields array
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: 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? kind regards and thanks in advance Tobias