I’m using Struts1.2 with Angular to post some data and want to get the data in java.
I’m able to retrieve the data from the server and able to display it in the scre
It is not data that you should use params
instead of data tag.
$scope.postData = function() {
var data = escape(angular.toJson($scope.items));
$http({
method: 'POST',
url: '/StrutsWithAngular/shopingCart.do',
params: 'cartValues='+data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data, status, headers, config) {
$scope.items = data;
}).error(function(data, status, headers, config) {
// alert("Error :: "+data);
});
};
Using the second try, before posting the data convert scope to json
This can be done either in two ways either using JSON api or Angular api
I used angular.toJson() and I also used escape method for accepting special characters.
Using request.getParameter you can get the value in the sever side. Hope solution helps everybody.
// Second Try
$scope.postData = function() {
var data = escape(angular.toJson($scope.items));
$http({
method: 'POST',
url: '/StrutsWithAngular/shopingCart.do',
data: 'cartValues='+data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data, status, headers, config) {
$scope.items = data;
}).error(function(data, status, headers, config) {
// alert("Error :: "+data);
});
};
Angular does not POST form data, it transmits a JSON object to the server. For information on JSON itself, see JSON.org. There are also a wealth of libraries listed on that page (towards the bottom) that let you parse JSON in various languages, including Java. Not being a Java developer, I can't say that one of them is better than the other, but you should be able to get a good idea of suitability by reading the docs on each one.