Based on the help availed from stackoverflow I created the table with hiddenfields to pass the value to servlet, but in servlet I am unable to get the values of the input fields.
Here is my jQuery code to create table:
$("#linkInstr").click(function() {
var arr = new Array();
var cdid = $("#cboinstr option:selected");
var code = $("#cbocode option:selected");
$.get("trnDC?caseNo=21&insid="+cdid.text(), function(data) {
arr = data.split(",");
var contents = '<tr><td><input type="checkbox" id="chk_select'+counter+'" /></td><td><input type="hidden" id="txtCodeid'+counter+'" value="'+code.text()+'"/> ' + code.text()+ '</td><td><input type="hidden" id="txtInstrid'+counter+'" value="'+cdid.text()+'"/>' + cdid.text() + '</td><td>' + arr[0] + '</td><td>' + arr[1] + '</td><td>' + arr[2] + '</td></tr>';
alert(contents);
$("#tblDetails").append(contents);
counter++;
})
})
And here is my Servlet code:
int noOfRows = Integer.parseInt(request.getParameter("noOfRows"));
for (int i = 0; i < noOfRows; i++) {
int j = i + 1;
String codeid = request.getParameter("txtCodeid" + i);
throw new Exception(request.getParameter("txtCodeid" + i));
String instrId = request.getParameter("txtInstrid"+i);
st.executeUpdate("insert into trndcdtls values(" +ccode +"," +fyear_code +"," +Dcno +"," + j +",'" + codeid +"','" + instrId + "','"+status+"')");
}
The exception is throwed purposefully by myself to check any value is availble on request, but it shows nothing.