第一种:通过获取缓冲流读取参数
public void registerUser(HttpServletRequest request, HttpServletResponse response)throws Exception { //直接获取请求参数,通过缓冲流读取数据 BufferedReader br=request.getReader(); String inputLine = ""; String json = ""; while ((inputLine = br.readLine()) != null) { json += inputLine; } br.close(); System.out.println(json); String result=mztManager.register(json); response.setContentType("text/html;charset=UTF-8"); response.getWriter().print(result); response.getWriter().flush(); }
第二种:通过ServletRequestUtils获取
String data = ServletRequestUtils.getStringParameter(request, "data", "");
时间: 2024-10-25 17:36:06