|
//HTTP头部Content-type为application/json,而非大部分框架自动解析的application/x-www-form-urlencoded格式,需要自行读取后解析
public static JSONObject service(JSONObject params, ActionContext context) throws ServletException, IOException{
HttpServletRequest req = (HttpServletRequest)context.get(ActionContext.REQUEST);
HttpServletResponse resp = (HttpServletResponse)context.get(ActionContext.RESPONSE);
receivePost(req);
return null;
}
public static String receivePost(HttpServletRequest req) throws IOException, UnsupportedEncodingException {
// 读取请求内容
BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream()));
String line = null;
StringBuilder sb = new StringBuilder();
while((line = br.readLine())!=null){
sb.append(line);
}
// 将资料解码返回
String reqBody = sb.toString();
System.out.println("resp:"+reqBody);
return reqBody; //URLDecoder.decode(reqBody, HTTP.UTF_8);
}
获取不到参数,怎么处理?
|
|