The getSubmittedFileName () method is undefined for type Part

I am trying to upload multiple files to servlet 3.0>. So this is my code. I get an error in the getSubmittedFileName () method. I don’t know why. Help !!

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    String description = request.getParameter("description"); // Retrieves
                                                                // <input
                                                                // type="text"
                                                                // name="description">
    Part filePart = request.getPart("file"); // Retrieves <input type="file"
                                                // name="file">
    String fileName = Paths.get(filePart.getSubmittedFileName())
            .getFileName().toString(); // MSIE fix.
    InputStream fileContent = filePart.getInputStream();
    // ... (do your job here)
}
+4
source share
2 answers

I had this problem before. Some guy helped me find the root of this problem, so here is the solution I got:

In the Java EE 7 DOC, you can see that the “Interface part” was added to it with the getSubmittedFileName method from servlet 3.1, and from the tomcat website you can see that Tomcat 7 implemented Servlet 3.0, so I had to switch from Tomcat 7 - Tomcat 8.0.x.

Literature:

+2

Servlet 3.0, getSubmittedFileName() .

", Servlet 3.1, " .

+1

Source: https://habr.com/ru/post/1663225/


All Articles