Saturday, July 7, 2012

Java Servlet Get Post Body

This is how to get the content of the Post body in a HTTP Request:

protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
       BufferedReader reader = req.getReader();
       StringBuilder inputStringBuilder = new StringBuilder();
       String line = null;
       while ((line = reader.readLine()) != null) {
               inputStringBuilder.append(line);
       }
}

No comments:

Post a Comment