servlet获取不到Angular4 post过来的参数
来源:互联网 发布:淘宝宝贝分类模板 编辑:程序博客网 时间:2024/06/05 06:04
副标题:Java如何从HttpServletRequest中读取HTTP请求的body
今天接触一个项目,前台用angular4 post访问后台,
this.httpService.post({ url: 'quality/IMSI_MO', IMSImsg: this.InputMsg, TIME1: time1, TIME2: time2}).subscribe(res => { this.dialing = res;});
public post(msg): Observable<any[]> { return this.http.post(this.domain + [msg.url], JSON.stringify(msg), {headers: this.headers} ).map(res => res.json() as any[]);}
后台用servlet接收参数。
发现用request.getParameter获取不到参数。
String imsi =request.getParameter("search_imsi");
发现imsi值是null,获取不到。而以往的JQuery ajax能获取到。
之前用Springmvc 能获取到angular4 post的值
public @ResponseBody List<Map<String, Object>> getLTEmesctime(@RequestBodyMap<String, String> map) {........}
查看angular post的报文和非angularpost的报文
报文主体部分传递的不同。angular传递了json,json字符串这个整体又没有参数对应。所以request.getParameter是获取不到的。
只能读取主体的json字符串内容,然后转成Map对象,从Map对象中获取响应的值。
Gson gson=new Gson();Map<String,String> resultMap=new HashMap<String,String>();BufferedReader br = request.getReader();String str, wholeStr = "";while ((str = br.readLine()) != null) {wholeStr += str;}System.out.println(wholeStr);if(!"".equals(wholeStr)) {Map<String, String> map =gson.fromJson(wholeStr,Map.class);String imsi =map.get("search_imsi"); String msisdn =map.get("search_msisdn"); String p_hour_start =map.get("search_p_hour_start"); String p_hour_end =map.get("search_p_hour_end"); System.out.println("Searchimsi传入search_imsi:" + imsi);System.out.println("Searchimsi传入search_msisdn:" + msisdn);System.out.println("Searchimsi传入search_p_hour_start:" + p_hour_start);System.out.println("Searchimsi传入search_p_hour_end:" + p_hour_end);
阅读全文
0 0
- servlet获取不到Angular4 post过来的参数
- request取不到post请求过来的参数
- thinkphp过滤post提交过来的数组(获取不到post过来的checkbox值)
- 得到post过来的参数
- android中获取前一个Activity传递过来的参数获取不到的问题
- tomcat7,ajax post参数后台获取不到的问题
- xmlhttp post传值servlet获取不到值
- servlet获取并解析post请求发送过来的xml字符串
- 获取post过来的stream数据
- Servlet获取表单提交过来的数据
- tomcat7以上,ajax post参数后台获取不到的问题,post参数大小不能大于2M的解决办法!
- AJAX获取不到java传过来的值
- liferay后台获取不到前台传过来的值
- 利用JS获取传过来的参数
- 获取页面传过来的所有参数
- JS获取Url传递过来的参数
- 获取url传过来的参数
- html中的js如何获取通过POST方法传递过来的参数,PHP调试时print_r ,var_dump的区别
- cursor的使用
- jvm探秘四:class类文件结构
- Unity Shader入门精要 阅读笔记四
- Linux日志文件系统(EXT4、XFS、JFS)及性能分析
- C#初识10 字符串1
- servlet获取不到Angular4 post过来的参数
- 【UGUI】公告菜单
- Web
- [博弈论][阶梯博弈] BZOJ 1115:POI2009 石子游戏Kam
- 网络原理以及对VM中VMnet0,VMnet1,VMnet8的理解
- 并发编程Semaphore and Exchanger
- ASP.NET MVC底层原理与框架
- CSS选择器
- RCNN算法