• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to read html table in servlet

 
Atanu Banerjee
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Members :

I have a table populated in servlet, with one column as "delete button".
This button when clicked, the row gets deleted and this code is written in a Javascript file. After user alters the table (deleting rows), a checkout button below the table is clicked, and user would be taken to another page (displaying summary info collected from modified table).

When checkout button is going to submit the modified table to another servlet, how this servlet is going to read the modified table ?
Simply put, how a servlet can read (row,cell) of a html table ?

Thanks in advance
Atanu
 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to achieve it would be to embed a form with the table values as hidden elements.
 
Atanu Banerjee
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you suggesting hidden select field approach ? Could you please paste some code snippet, what you mean ? Thanks.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An HTML table can't be submitted to a servlet. What you can submit is an HTML form; so for any write or delete operations you need to construct an HTML form that submits all relevant data to the servlet (maybe the ID of the data to be deleted).
 
Atanu Banerjee
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I do something like this to achieve, as I described in my first mail ?

On user's clicking the "checkout" button call a javascript function which will read the (modified) table elements in array and send it to the final servlet, for it to collect & display summary info ?

If someone could please review this idea and post the syntactical summary -do appreciate very much. Thanks.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use Javascript to POST a message to the next servlet. Let each line of the POSTed text contain row, column, textdata

1,5,"no way"

the receiving servlet will have to parse the input stream - ie you cant use the regular form style getParameter().

Alternately you could POST a message emulating a form, building a "name" from the row and column and use getParameterMap().

1.5=no way

Bill
 
Srikanth Nutigattu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a table populated in servlet...


I don't consider making things complex.... Your's is a simple case and it has a very simple solution:

As you said you populate the table using a servlet, I assume that you have the data, more over you are not entering or modifying the data in table but simply "deleting the rows".

If you need I can paste the code for you, but its really simple and I think you can do it yourself.

You can use the following steps:

1. In the servlet that populates the table, along with the rows insert a hidden field "id" and set its "value" to a unique key to identify the row.
(eg: you can use the primary key if each row represents each record in db)

2. You can "Delete the rows" from the table using a simple "Java Sript function" when you click the delete row button.

3. The entire table should be inside <form> and when you click the submit button, all the "hidden fields" will be submitted which represents the rows that are not deleted.

4. Using the ServletRequest's getParameterValues() or if it is Jsp, you can use EL implicit object 'paramValues["id"]' to retrieve the array of submitted "id"'s.

Now, as you got the keys, you can identify which rows are submitted.

As simple as that!

Thanks!
 
Atanu Banerjee
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody for eloquent suggestions. But I adopeted William's getParameterMap() approach - thinking of long term usage of this application.

I'd be still interested to know the syntax of sending/receiving of array from/to javascript/servlet. Could someone throw some light on this please ?

Thanks very much.
Atanu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic