Here is my Angular Code(Get request is working fine but not Post request. I am receving null in carrier_id on Servlet side).
app.js
var app = angular.module( "admin" , []);
app.config(function ($httpProvider){
// set the Content-Type header globally
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// define ajax call behavior globally
// set up global transformRequest function
$httpProvider.defaults.transformRequest = function(data){
if (data === undefined) {
return data;
}
return $.param(data);
};})
app.controller('mainController', function($scope, $http, $window){
$scope.fileList =[];
$scope.selectedFile = null;
$http({
method: 'GET',
url :'hrp/filelist'
}).success( function(data,status,headers,config){
data.file_list.splice(0, 1) // to remove header row
$scope.fileList=data.file_list
}).error(function(){
alert("error")
})
$scope.submitFile = function(selectedFile){
console.log("happy" + selectedFile);
$http({
method: 'POST',
url: 'hrp/carrierInfo',
data: {carrier_id: selectedFile}
}).success(function(data){
alert(data.carrier_id + " & " + data.method_name)
}).error(function(){
alert("errors")
})
}});
And part of Servlet Code:
String carrier_id = (String)request.getAttribute("carrier_id");
response.setContentType("application/json");
but it is null.