request.getInputStream() 的两种解析方式

request 内容解析方式:

方式一:

byte[] bytes = new byte[1024 * 1024];
			InputStream is = request.getInputStream();

			int nRead = 1;
			int nTotalRead = 0;
			while (nRead > 0) {
				nRead = is.read(bytes, nTotalRead, bytes.length - nTotalRead);
				if (nRead > 0)
					nTotalRead = nTotalRead + nRead;
			}
			String str = new String(bytes, 0, nTotalRead, "utf-8");
			System.out.println("Str:" + str);

 方式二:

BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream()));
			String line = null;
			StringBuilder sb = new StringBuilder();
			while ((line = br.readLine()) != null) {
				sb.append(line);
			}
			System.out.println(sb);
 

头参数解析方式

 

String params = request.getQueryString();

private Map getRequestParam(String params){
		Map paramMap = null;
		if(null!=params){
			paramMap = new HashMap();
			String param[]=params.split("&");
     	   for(int i=0;i
 

你可能感兴趣的:(web前端)