作者:铥铥宇900 | 来源:互联网 | 2023-05-16 11:45
So,inmyangularapplication,ImtryingtohandleasaveontheserversidewithJSP.Theproblem
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. ???
因此,在我的角度应用程序中,我尝试使用JSP来处理服务器端上的save。我遇到的问题是,当使用角的$save方法时,它将对象数据(我正在保存的对象)作为JSON对象发送,但不是以我使用的任何方式发送。该对象不能通过request. getparameter()访问,当查看firebug中的请求时,我可以看到它没有发送JSON或具有任何参数。相反,它在“POST”部分中发送json对象。我不太明白这是怎么回事。? ? ?
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)
角的文章的默认内容类型是“application/json”,因此如果您将其更改为“application/ www-form- urlencodes;charset=utf-8”,您至少可以使用request.getParameter()获得json对象的参数(如果您还更改了json对象的传输方式)
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.
首先这不是真正的问题,因为如果我使用jQuery.ajax()请求并将contentType设置为application / json,然后通过json对象数据,然后我仍然得到json对象属性作为参数,所以我可以使用request.getParameter(),你就不要让url的查询字符串。
SOOO, my questions are:
呃,我的问题是:
1) What the heck is going on with the way Angular sends it's data
1)角传送数据的方式到底是怎么回事
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
2)我是否可以在使用$resource $save函数的同时更改它(更改$http的内容类型在使用$resource方法时有一些不好的影响),最重要的是
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.
3)如果我不能更改它(或者即使我可以),那么如何在JSP中解析json数据和它现在的工作方式。
Your help is much appreciated, I can't believe I can't find something about this yet, I've been looking for a while.
非常感谢您的帮助,我真不敢相信我还找不到什么,我已经找了一段时间了。
1 个解决方案