I am building a web-based application by using Java servlet and AngularJs.
Previously, I just use $http (the following code), every things is fine.
this.callWithParam = function(command) {
var deferred = $q.defer();
$http({
method: 'POST',
url: 'SearchServlet',
data: $.param({'data': JSON.stringify(command)}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data) {
deferred.resolve(data);
}).error(function() {
deferred.reject('Error occur!');
});
return deferred.promise;
}
But I want to revise it into $resource, because I find that it is really convenience and can save a lot of code. So I write the following code
search: function() {
return $resource('SearchServlet', {}, {
'searchA': {method: 'GET', headers:{'Content-Type': 'application/x-www-form-urlencoded'} },
'searchB': {method: 'GET', headers:{'Content-Type': 'application/x-www-form-urlencoded'} }
});
}
But I found that the header failed to add to the request headers, then it has the problem to due with Chinese character, so the servlet cannot well receive the Chinese words.
Therefore, anyone has the idea to solve this problem? Thanks!