问题描述
我有3个输入字段的动态数量的字段集,每个字段的排序方式不同,例如:
< fieldset> ;
< input type =textname =fieldset [1] [valueA]>
< input type =textname =fieldset [1] [valueB]>
< input type =textname =fieldset [1] [valueC]>
< / fieldset>
< fieldset>
< input type =textname =fieldset [2] [valueC]>
< input type =textname =fieldset [2] [valueB]>
< input type =textname =fieldset [2] [valueA]>
< / fieldset>
我想在循环中访问Java servlet中的这些字段,但我不知道如何使用这些字段。
使用输入的名称可以这样做
fieldset [n] []
字段集[1]
String []元素;
elements = request.getParameterValues(fieldset [1] );
for(int i = 0; i< elements.length; i ++){
out.write(elements [i]);
}
但是有什么办法可以做到这一点,同时将信息保存在第二个括号中?
看来使用[]符号会导致问题。 $ b
HttpServletRequest.getParameterValues()
可以像下面的链接一样循环。
勾选这个
I've got a dynamic number of fieldsets with 3 input fields each ordered differently, for example:
<fieldset>
<input type="text" name="fieldset[1][valueA]">
<input type="text" name="fieldset[1][valueB]">
<input type="text" name="fieldset[1][valueC]">
</fieldset>
<fieldset>
<input type="text" name="fieldset[2][valueC]">
<input type="text" name="fieldset[2][valueB]">
<input type="text" name="fieldset[2][valueA]">
</fieldset>
I would like to access these fields within a Java servlet in a loop, but I don't know how to adress these fields.
It would be possible with the input's name this way
fieldset[n][]
and a loop this way (to access the fields of fieldset[1]
String[] elements;
elements = request.getParameterValues("fieldset[1]");
for(int i = 0; i < elements.length; i++) {
out.write(elements[i]);
}
But is there any way I can do this and at the same time keep the information in the second bracket?
It seems The using [] notation causing the problem .
The HttpServletRequest.getParameterValues()
can loop like in the below link.
check this answer
这篇关于访问Java Servlet中的HTML输入字段数组/输入字段的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!