在Java中,可以通过Servlet中的request对象来获取POST请求中的数据。具体步骤如下:
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异常。