• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

how to read html table in servlet

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you suggesting hidden select field approach ? Could you please paste some code snippet, what you mean ? Thanks.
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic