在Java中,可以通過Servlet中的request對象來獲取POST請求中的數(shù)據(jù)。具體步驟如下:
BufferedReader reader = request.getReader();
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
String postData = sb.toString();
String parameterValue = request.getParameter("parameterName");
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> postDataMap = objectMapper.readValue(postData, new TypeReference<Map<String,Object>>(){});
注意:在使用request.getReader方法時,需要注意處理可能拋出的IOException異常。