I need to get the value from client side to server side. I am using AngularJS and Struts2 REST. Newbie in AngularJS here. My controller doesn\'t get the value passed or am i wro
Since angular service is sending JSON, you can send a JSON object using data
property. The JSON object will be deserialized to your model class properties because you are using ModelDriven
or action class properties otherwise.
Struts2 REST plugin is made to handle JSON content from the request. It's possible due ContentTypeInterceptor
, which is called rest
, be able to find JSON handler for the request. The JSON handler is guessed from the Content-Type
header or extension to the file in the URL. You can use either ways, but second is easier.
Note: that URLs without a file extension the Struts2 REST plugin defaulting to handle xhtml content. So you can modify your code
$http({
method: "POST",
url: "api/additionalcategory.json",
data: {}
}).success(function(data, status, header, config){
//success
}).error(function(data, status, header, config){
//error
});