File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Submitting a table in a form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Submitting a table in a form" Watch "Submitting a table in a form" New topic
Author

Submitting a table in a form

Jay Brass
Ranch Hand

Joined: Oct 24, 2000
Posts: 76
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jay Brass
Ranch Hand

Joined: Oct 24, 2000
Posts: 76
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

To retrieve multiple elements that share the same name use request.getParameterValues().
Jay Brass
Ranch Hand

Joined: Oct 24, 2000
Posts: 76
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Submitting a table in a form