• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Submitting a table in a form

 
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To retrieve multiple elements that share the same name use request.getParameterValues().
 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Hoo hoo hoo! Looks like we got a live one! Here, wave this tiny ad at it:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic