So, in my angular application, I'm trying to handle a save on the server side with JSP. The problem I'm having is that when using Angular's $save method, it sends the object data (the object I'm saving) as a JSON object, but not in any way that I'm use to. The object is not accessible through the request.getParameter() and when looking at the request in firebug, I can see it does not send JSON or have any parameters. Instead, it sends the json object in the "POST" part. I don't quite understand what's going on here. ???
So here's what I know so far:
The default contentType for posts in Angular is "application/json", so if you change that to be "application/x-www-form-urlencoded;charset=utf-8" you can at least get the parameters of the json object using request.getParameter() (if you also change the way the json object is transmitted)
BUT
This isn't really the problem in the first place because if I use jQuery.ajax() to make a request and set the contentType to "application/json" and then pass the json object as data, then I still get the json object attributes as parameters so I can use request.getParameter(), you just don't get the query string in the url.
SOOO, my questions are:
1) What the heck is going on with the way Angular sends it's data
2) Is there any way I can change it while still being able to use the $resource $save function (changing the contentType of the $http has some bad effects when using $resource methods), and, most importantly
3) If I can't change it (or even if I can), how do you parse the json data in a JSP with the way it works now.
Your help is much appreciated, I can't believe I can't find something about this yet, I've been looking for a while.
Well, in case anybody was wondering about this:
I still don't really understand why angular and jquery "post" methods act differently when giving them the same dataType ("application/json"), but as far as I can tell it seems that Angular uses REST and I'm guess JQuery does not?
As far as how to parse the json on the server side, just see this post: Retrieving JSON Object Literal from HttpServletRequest