1. 程式人生 > >Servlet裏面request處理外部POST請求的輸入流的工具類

Servlet裏面request處理外部POST請求的輸入流的工具類

ace exceptio 輸入流 exception tac append clas blog trac

package etcom.servlet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.servlet.http.HttpServletRequest;

public class IoToJsonUtils {
    
    public static String getIoToJson(HttpServletRequest request,String code){
        String jsonString 
= null; try { InputStream in = request.getInputStream(); InputStreamReader isr = new InputStreamReader(in,code); BufferedReader reader = new BufferedReader(isr); String inputString = null; StringBuffer stringBuffer = new StringBuffer();
while ((inputString = reader.readLine()) != null) { stringBuffer.append(inputString); } reader.close(); jsonString = stringBuffer.toString(); System.out.println(jsonString); } catch (IOException e) { // TODO Auto-generated catch block
e.printStackTrace(); } return jsonString; } }

Servlet裏面request處理外部POST請求的輸入流的工具類