该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

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 : byte[]

* @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[] 数组

*

* 举例:

*

* @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 请求内容

*

* 举例:

*

* @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);

}

}

java request get json数据_Java中,获取request中json数据相关推荐

  1. java匹配字符串所在位置_Java:获取字符串中匹配项位置的方法?

    宝慕林4294392 执行此操作的方法家族是:int indexOf(String str)indexOf(String str, int fromIndex)int lastIndexOf(Stri ...

  2. mysql java 获取周_Java中获取Mysql中datetime类型的数据

    由于Java中的日期类型只有Date类型,而Mysql中即有date型,又有datetime型,当我们想要在java中获取Mysql中datetime类型的数据或向Mysql数据库中插入datetim ...

  3. java定时器任务中获取request对象 @Scheduled 获取request 对象 quartz中获取request对象

    java定时器任务中获取request对象 @Scheduled 获取request 对象 quartz中获取request对象 一.问题描述 1.在java定时任务中,使用 @Scheduled 注 ...

  4. Spring 中获取 request 的几种方法,及其线程安全性分析

    概述 在使用Spring MVC开发Web系统时,经常需要在处理请求时使用request对象,比如获取客户端ip地址.请求的url.header中的属性(如cookie.授权信息).body中的数据等 ...

  5. Spring中获取request的方法及其线程安全性分析

    在使用Spring MVC开发Web系统时,经常需要在处理请求时使用request对象,比如获取客户端ip地址.请求的url.header中的属性(如cookie.授权信息).body中的数据等.由于 ...

  6. Spring MVC中获取Request的方法及分析

    一.概述 在使用Spring MVC开发Web系统时,经常需要在处理请求时使用request对象,比如获取客户端IP地址.请求的URL.header中的属性(如cookie.授权信息).body中的数 ...

  7. SpringMvc4中获取request、response对象的方法

    springMVC4中获取request和response对象有以下两种简单易用的方法: 1.在control层获取 在control层中获取HttpServletRequest和HttpServle ...

  8. spring MVC中获取request和response

    spring MVC中获取request和response: Java代码   HttpServletRequest request = ((ServletRequestAttributes) Req ...

  9. server sql 数据总行数_SqlServer中获取数据库中每个表的行数

    CREATE TABLE #RowCounts(NumberOfRows BIGINT,TableName VARCHAR(128)) EXEC sp_MSForEachTable 'INSERT I ...

  10. Java中获取数据库中两个时间的相差秒数

    场景 Java中获取数据库中结束时间与开始时间相差的秒数. 实现 Long betweenTime=0l;betweenTime =((b.getFinishTime().getTime()-b.ge ...

最新文章

  1. python操作mongodb进行读写
  2. (水题)987654321 problem -- SGU 107
  3. C++STL之next_permutation使用
  4. 成功解决连接SQL输出出现中文乱码问题(10001, 'oracle¿ìËÙÈëÃÅ', 'Íõº£ÁÁ', 'Ë®Àû³ö°æÉç',
  5. eclipse序列化生成serialVersionUID
  6. Hello Python程序演练
  7. test of ui5 duplicate control id
  8. 蓝桥杯评测_前n项和
  9. Android add external jar
  10. EasyExcel简单使用
  11. 【Kafka】Kafka幂等性原理及实现剖析
  12. ShadeGraph教程之节点详解2:Channel Nodes
  13. spring 事物配置几种
  14. HttpClient 4.0.x Tips
  15. js禁止输入框输入特殊符号或emoji表情
  16. AAC的ADTS头解析
  17. 视频分类之 UCF-101 上的 CNN 方法详解
  18. 第3章 远程连接管理Linux实践
  19. eclipse的中文版本安装方法
  20. 让 Google 搜索到自己的博客

热门文章

  1. ARM:钒和铁替代固氮酶的前世今生
  2. R语言ggplot2可视化绘制Marimekko/Mosaic图实战:自定义函数绘制Marimekko/Mosaic图(添加数值、标题、色彩配置)、ggmosaic包绘制Marimekko图
  3. R语言dplyr包将dataframe中的NA值替换(replace)为0实战:所有NA值替换(replace)为0、具体列的NA值替换(replace)为0、若干列的NA值替换(replace)为0
  4. python使用openweathermap API获取全世界主要城市天气信息
  5. prefetch下载SRA 数据
  6. 在高中生物里我们提到和遗传有关的物质有染色体,染色质,基因,dna
  7. Oxford Nanopore碱基识别(basecalling)软件性能大比拼
  8. SQLite - 下载安装与使用(Command Line Shell For SQLite)
  9. Oracle Database 11g的使用
  10. Assembly--软件PBcR和Canu