[Logo]
Forums Register Login
Submitting a table in a form
Hey there,
I have a JSP page that displays data in a table from a database. The rows are created based on the results from the database. Basically there are some textfields that allow a user to enter in stuff, when they click on the search button a servlet builds a prepared statement based on the parameters in the textfields. The database returns a result and this is displayed on the JSP page. I want to save the results in a new table and allow the user to search for new data. Then I will submit this new table which will be the result of multiple queries. My problem is that I don't know how to get the results of the first table into my servlet. I know that there is an elements array of all the form fields in my form on my JSP page, but when I submit my form to the servlet, I only see the first row of data in the table. Is there some DOM thing I'm missing? How do I get the elements array into the servlet? Do I have to build a document? I realize some of the things here might be complex and that submitting a table from a JSP page that has multiple rows with elements that have the same name, might be rather basic, but I would really appreciate the help.

Thanks in advance,

~J
Is the whole table in a single form, or is each row its own form?

If a single form, are you assigning the same name for each element in the rows? If so, all the rows are being submitted but you may bt be accessing them correctly to retrieve all the values.

More info is needed to answer the above questions.
Yeah, the table is in its own form so all of the rows are in 1 form. Each row element is named the same throughout the table.

For example:
For Row 1 LName FName EmpID
For Row 2 LName FName EmpID
For Row 3 LName FName EmpID

I know that there should be a number appended to the names when I retrieve them, but I don't know how to access them in the servlet when the form is submitted.

Many thanks for your advice,

~J
To retrieve multiple elements that share the same name use request.getParameterValues().
Yeah that is working, providing that each <td> cell has an input field(like a textfield) in it. The <td> cells that don't have an input field don't show up as parameters in the servlet and I don't get the data they contain.
Thanks for your advice.

~J
Another tactic is to not name the fields the same in each row, but to use a row number as a suffix. Then on the server you can fetch them by number/row.
 
Originally posted by Jay Brass:
Yeah that is working, providing that each <td> cell has an input field(like a textfield) in it. The <td> cells that don't have an input field don't show up as parameters in the servlet and I don't get the data they contain.
Thanks for your advice.

~J


That's correct, a table is not a form element.
You will need to put a valid form element (such as a text input field) in each cell if you want the values to be submitted with the form.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 22, 2017 09:51:06.