protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Collectionparts = request.getParts(); for (Part part : parts) { String fileName = part.getSubmittedFileName(); InputStream fileContent = part.getInputStream(); // Do something with the file } }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Part part = request.getPart("username"); String username = new BufferedReader(new InputStreamReader(part.getInputStream())).readLine(); // Do something with the username }This example shows how to retrieve a specific part of a request with the name "username" and read its content as a string. The library used for HttpServletRequest and Part objects is the javax.servlet.http package.