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>
<div class="x_content">
<table id="myTable" class="table table-striped table-bordered" width="100%"></table>
</div>
<script>
function saveData() {
$.ajax({
type: 'POST',
url: 'AddLicenceServlet',
data: 'data',
headers: {
Accept: "application/json; charset=utf-8",
"Content-Type": "application/json; charset=utf-8"
},
success: function () {
var table = $('#myTable').DataTable();
var data = table.rows().data();
request.setAttribute("data", data);
console.log(data);
alert('success insert' + data);
}
});
}
;
<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)
in the "success" shows well the updated data that I would like to retrieve in my servlet and the call of the servlet is working 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);
LicenceDAO licenceDAO = new LicenceDAO();
List<Licence> licenceList = (List)request.getAttribute("data");
for (Licence c : licenceList) {
c.setSerialNumber(request.getParameter("pk.serialNumber"));
c.setSoftware(request.getParameter("pk.software"));
c.setCustomer(request.getParameter("customer"));
c.setName(request.getParameter("name"));
licenceDAO.persist(c);
}
}
How can I retrieve the data from the table in the client side to my servlet in the server side using Ajax ? Did I miss something to make the communication between jsp and servlet possible ?
I'm new in servlet/jsp/ajax, any help would be great! Thanks a lot!