I have a jsp file where on a button click a bunch of rows shows up in a html table format.
The rows have checkboxes as well. When I click a checkbox and hit another button i am able to retrieve the selected row tags and push them into an array.
How can I pass this array to the servlet\scriptlet.
Array consists of tags like so: '< td > hi < /td> <td>ho</td>','< td > hi < /td> <td>ho< /td>',….
I included json2.js and tried stringify but servlet always comes back saying null when i use request.getparametervalues()
i also dont have a submit form so that rules out the submit form part of the coding.
Any and all advices very much appreciated.
code in js:
$.ajax({
type: 'POST',
url: 'book.jsp',
data: JSON.stringify({ nameParameter: colheader }),
dataType: 'json',
contentType: "application/json; charset=utf-8",
success:function(data){alert(data);},
error:function(){alert('error');}
});
Code in scriptlet book.jsp
String[] arrayData=request.getParameterValues("nameParameter");
System.out.println("########nameParameter"+arrayData);
I found a way to do it.
I add a rowid to each checkbox with the value of the primary key.
On selected a checkbox I post the rowid’s to the scriptlet using the below
selectedrows is an array of selected rowids.
I set the resultset obtained into the session in the jsp.
I retrieve the resultset from the session in my scriptlet (target.jsp) and filter based on my selected rowids. That way I have all the values and need not pass the entire rowtag.
Alternatively you can query the database again with the selected rowid’s, I chose not to do it as my resultset does not hold more than 100 rows.