if(request.getParameter("btnadd")!=null) {
int eId = Integer.parseInt(request.getParameter("eId"));
String datepicker = request.getParameter("datepicker");
String name = request.getParameter("name");
String cmp = request.getParameter("cmp");
String insertRecord = dataBaseEngine.insertDepartment(eId, datepicker, name, cmp);
String btnadd = String.valueOf(insertRecord);
response.setContentType("application/json");
out.print("{\"btnadd\" : \"" + btnadd + "\"}");
out.flush();
out.close();
request.getRequestDispatcher("").forward(request, response);
response.sendRedirect("");
}
AngularJs代码
$scope.btnadd = function() {
$.ajax({
url: 'Srvlet',
type: "POST",
data: {
eId: $scope.newcontact.eId,
datepicker: $scope.newcontact.datepicker,
name: $scope.newcontact.name,
cmp: $scope.newcontact.cmp
},
success: function(data, textStatus, jqXHR) {
console.log(data);
$scope.$apply(function(){
$scope.newcontact.btnadd = data.btnadd;
});
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('Error : ' + jqXHR.responseText);
}
});
};