retrieve data from dataTables in jsp to servlet
retrieve data from dataTables in jsp to servlet
I have an editable DataTables (jQuery) that shows the data from my DB in my jsp. I try with no success to retrieve in a servlet the list of objects updated (after modification of the data by a user in the client side) wich are in this DataTables... A "save" button is here to trigg the process.
Here is part of my jsp :
<button onclick="saveData()">SAVE</button>
<script>
function saveData() {
var table = $('#myTable').DataTable();
var data = table.rows().data();
console.log(data);
document.location.href="AddLicenceServlet";
}
</script>
<div class="x_content">
<table id="myTable" class="table table-striped table-bordered" width="100%"></table>
</div>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: 'GET',
url: 'http://localhost:8080//RedlogServer3/licences',
dataType: 'json',
headers: {
Accept: "application/json; charset=utf-8",
"Content-Type": "application/json; charset=utf-8"
},
success: function (response) {
var dataTablesObj = response;
generateDataTable(dataTablesObj);
dataSet = dataTablesObj.data;
},
error: function (resultat, statut, erreur) {
},
complete: function (resultat, statut) {
}
})
});
</script>
The console.log(data) shows well the updated data that I want to retrieve in my servlet, so the function "saveData works for that part of the job... The call of the servlet is working to but I don't retrieve any data... The "request.getParameter" are "null"...
Here is my servlet :
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
DataService ds = new DataService();
try {
ds.getLicences();
} catch (ObjectNotFoundException ex) {
Logger.getLogger(AddLicenceServlet.class.getName()).log(Level.SEVERE, null, ex);
}
Licence c = new Licence();
LicenceDAO licenceDAO = new LicenceDAO();
c.setSerialNumber(request.getParameter("serialNumber"));
c.setSoftware(request.getParameter("software"));
c.setCustomer(request.getParameter("customer"));
c.setName(request.getParameter("name"));
c.setValidityDate(java.sql.Date.valueOf(request.getParameter("validityDate")));
licenceDAO.persist(c);
}
How can I retrieve my data from the table in the client side to my servlet in the server side ? Did I miss something to make the communication between jps and servlet possible ?
I'm new in servlet/jsp, any help would be great! Thanks a lot!