Implement the submission of dynamic text boxes and their values ​​in JSP beans
P粉916760429
P粉916760429 2023-12-11 11:56:28
0
1
428

I have a form with a few predefined textboxes and now apart from that I have also created some dynamic textboxes and I can do it with javascript (I guess). How to set the value of a dynamically generated textbox to a bean when a form is submitted. In the bean, I defined a string array to hold the contents of the dynamically generated textbox value. I am not using any framework, please guide me how to do this?

P粉916760429
P粉916760429

reply all(1)
P粉884548619

You can give all input fields the same name and then use request.getParameterValues() to get all values ​​in the order they appear in the HTML DOM tree.

For example (JavaScript generation)

<input type="text" name="foo" />
<input type="text" name="foo" />
<input type="text" name="foo" />
...

and

String[] values = request.getParameterValues("foo");
// ...

You can also add incrementing numbers after the name, such as foo1, foo2, foo3, etc. and collect the values ​​in a loop until ## is received #null.

For example

<input type="text" name="foo1" />
<input type="text" name="foo2" />
<input type="text" name="foo3" />
...
and

List<String> foos = new ArrayList<String>();

for (int i = 1; i < Integer.MAX_VALUE; i++) {
    String foo = request.getParameter("foo" + i);
    if (foo == null) break;
    foos.add(foo);
}

// ...
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!