热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用jsp从角度读取json-readingjsonsentfromangularwithjsp

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 个解决方案

#1


0  

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?

我仍然不理解为什么在提供相同的数据类型(“application/json”)时,角化方法和jquery“post”方法的作用是不同的,但是据我所知,角化方法似乎使用了REST,我猜jquery没有呢?

As far as how to parse the json on the server side, just see this post: Retrieving JSON Object Literal from HttpServletRequest

至于如何在服务器端解析json,请参阅本文:从HttpServletRequest检索json对象文本


推荐阅读
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 阿,里,云,物,联网,net,core,客户端,czgl,aliiotclient, ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • 利用Visual Basic开发SAP接口程序初探的方法与原理
    本文介绍了利用Visual Basic开发SAP接口程序的方法与原理,以及SAP R/3系统的特点和二次开发平台ABAP的使用。通过程序接口自动读取SAP R/3的数据表或视图,在外部进行处理和利用水晶报表等工具生成符合中国人习惯的报表样式。具体介绍了RFC调用的原理和模型,并强调本文主要不讨论SAP R/3函数的开发,而是针对使用SAP的公司的非ABAP开发人员提供了初步的接口程序开发指导。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
author-avatar
八戒走你
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有