获取 request 中 json 数据
import java.io.IOException; import javax.servlet.http.HttpServletRequest; /** * request 对象的相关操作 * @author zhangtengda * @version 1.0 * @created 2015年5月2日 下午8:25:43 */ public class GetRequestJsonUtils { /*** * 获取 request 中 json 字符串的内容 * * @param request * @return : <code>byte[]</code> * @throws IOException */ public static String getRequestJsonString(HttpServletRequest request) throws IOException { String submitMehtod = request.getMethod(); // GET if (submitMehtod.equals("GET")) { return new String(request.getQueryString().getBytes("iso-8859-1"),"utf-8").replaceAll("%22", "\""); // POST } else { return getRequestPostStr(request); } } /** * 描述:获取 post 请求的 byte[] 数组 * <pre> * 举例: * </pre> * @param request * @return * @throws IOException */ public static byte[] getRequestPostBytes(HttpServletRequest request) throws IOException { int contentLength = request.getContentLength(); if(contentLength<0){ return null; } byte buffer[] = new byte[contentLength]; for (int i = 0; i < contentLength;) { int readlen = request.getInputStream().read(buffer, i, contentLength - i); if (readlen == -1) { break; } i += readlen; } return buffer; } /** * 描述:获取 post 请求内容 * <pre> * 举例: * </pre> * @param request * @return * @throws IOException */ public static String getRequestPostStr(HttpServletRequest request) throws IOException { byte buffer[] = getRequestPostBytes(request); String charEncoding = request.getCharacterEncoding(); if (charEncoding == null) { charEncoding = "UTF-8"; } return new String(buffer, charEncoding); } }
获取 request 中 json 数据的更多相关文章
- Go net/http获取body中json格式数据
Go net/http获取body中json格式数据 package main import ( "encoding/json" "fmt" "io/ ...
- Jquery Ajax和getJSON获取后台普通Json数据和层级Json数据解析
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 基于BootStrap的initupload()实现Excel上传和获取excel中的数据
简单说明:后边要做exl解析(还没做呢),所以先有一个excel的的上传以及获取excel中的数据,展示出来. 代码: //html代码 <div class="btn-group&q ...
- js中json数据简单处理(JSON.parse()和js中嵌套html)
js中json数据简单处理(JSON.parse()和js中嵌套html) 一.总结 1.html中嵌套js:<script>js代码</script> 2.js中嵌套html ...
- Springboot中使用自定义参数注解获取 token 中用户数据
使用自定义参数注解获取 token 中User数据 使用背景 在springboot项目开发中需要从token中获取用户信息时通常的方式要经历几个步骤 拦截器中截获token TokenUtil工具类 ...
- php获取数组中重复数据的两种方法
分享下php获取数组中重复数据的两种方法. 1,利用php提供的函数,array_unique和array_diff_assoc来实现 <?php function FetchRepeatMem ...
- java获取request中的参数、java解析URL问号后的参数
java获取request中的参数.java解析URL问号后的参数.有时候我们需要从request中获取参数,或者获取拼接在Url后面的参数,有时候一个一个去拿有点麻烦,一起拿出来放在一个map里面需 ...
- 获取request中的查询参数
//获取request中的查询参数 public static Map<String, Object> getRequestParamsByMap(HttpServletRequest r ...
- jquery中json数据转换为字典
首先在前台页面中的json数据为 var recipe = {}; recipe["name"] = $("#name").val(); recipe[&quo ...
随机推荐
- CodeForces 689C【二分】
转自: http://blog.csdn.net/qq_26071477/article/details/51892995 #include<stdio.h> typedef long l ...
- 在mpvue框架中使用Vant WeappUI组件库的注意事项
1如何引入组件库 有两种方法 1 npm下载 2 下载代码,下面介绍第二种方法. 在gitHub上, 链接如下 https://github.com/youzan/vant-weapp 首先在自己项目 ...
- DBUtils C3P0 阿里巴巴德鲁伊连接池工具的下载
- stringstream转换
在这之前,在杭电刷题的时候,并没有注意到这个好东西. 使用stringstream对象简化类型转换C++标准库中的<sstream>提供了比ANSI C的<stdio.h>更高 ...
- [題解](最短路/二分)luogu_P1462通往奧格瑞瑪的道路
看到最大的最小值應該想到二分答案,這樣就解決了最小點權的問題,判血量就很好說,直接比較就行, 一個點是二分點權數組,複製一份然後排序,二分下標,速度較快 這麼簡單的題我竟然寫了這麼長時間 #inclu ...
- JS 两个数组合并
让我们先考虑下面这情况: 代码如下: var a = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];var b = [ "foo", "bar", ...
- Django (六) 视图 views
views 1. 视图及HttpRequest 和HttpResponse Django中的视图主要用来接受Web请求,并做出响应. 视图的本质就是一个Python中的函数 视图的响应分为两大类 1) ...
- Codeforces Round #542(Div. 2) B.Two Cakes
链接:https://codeforces.com/contest/1130/problem/B 题意: 给定n和 2 * n个数,表示i位置卖ai层蛋糕, 有两个人在1号,必须严格按照1-n的顺序买 ...
- Windows忘记mysql的密码
1.查看mysql的安装路径 show variables like "%char%"; 路径:C:\Program Files\MySQL\MySQL Server 5.7\ 2 ...
- hihocoder1777 彩球
思路: 记录一下快速幂计算过程中爆long long的两种解决方法: 1. 使用__int128,这玩意本地编译不通过,提交OJ能AC. 实现: #include <bits/stdc++.h& ...