1

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?

1 Answer 1

0

It seems The using [] notation causing the problem .

The HttpServletRequest.getParameterValues() can loop like in the below link.

check this answer

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.