0

I'm trying to retrieve a file from a JSP form. I'm using Tomcat 9.0 / Java 8

When I compile, I got the messages :

addHabit.java:56: error: cannot find symbol String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString();
symbol: method getSubmittedFileName() location: variable filePart of type Part

addHabit.java:56: error: cannot find symbol String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString();
symbol: variable Paths

My code is pretty simple and looks like everything I found here and on the web :

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import javax.sql.*;
import java.sql.*;
import java.util.*;
import com.microsoft.sqlserver.jdbc.*;

// Appelé par le JSP addConfigType.jsp via l'action du formulaire

@MultipartConfig(
  fileSizeThreshold = 1024 * 1024 * 1, // 1 MB
  maxFileSize = 1024 * 1024 * 10,      // 10 MB
  maxRequestSize = 1024 * 1024 * 100   // 100 MB
)
public class addHabit extends HttpServlet{ 
 
   public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
    {
        HttpSession session = request.getSession(false);

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();     
        String url="myURL";
        
        Part filePart = request.getPart("monfichier");          
        String fileName =  Paths.get(filePart.getSubmittedFileName()).getFileName().toString();             
         for (Part part : request.getParts()) {
            part.write(url);                
        }
    }
}

I compile using javax.servlet-api-3.0.1 According to this post How can I upload files to a server using JSP/Servlet? it should be fine

Can you help me ?

Pandalex
  • 23
  • 7

1 Answers1

2

The docs of that method state:

Since:
Servlet 3.1

that means that your javax.servlet-api-3.0.1 is too old. There is a version 3.1.0 available.

I just realized that the question you linked also provides these answers already, as well as a copy-pastable workaround, have you read that question and answer?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
f1sh
  • 11,489
  • 3
  • 25
  • 51