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
424

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)

   ...

and

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

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

For example

   ...
and

List foos = new ArrayList(); 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!