1

I am getting following error in jsp page for file upload code:

The method parseRequest(RequestContext) in the type FileUploadBase is not applicable for the arguments (HttpServletRequest)

error in the code:

List<FileItem> items = uploadHandler.parseRequest(request);
1
  • The method parseRequest(RequestContext) in the type FileUploadBase is not applicable for the arguments (HttpServletRequest)...this is the error message while compiling Commented Dec 16, 2014 at 8:27

3 Answers 3

8

The parseRequest(RequestContext ctx) expects RequestContext instance as argument but the argument passed is instance of HttpServletRequest

Use ServletRequestContext to create a RequestContext instance as follows.

List<FileItem> items 
          = uploadHandler.parseRequest(new ServletRequestContext(request));
Sign up to request clarification or add additional context in comments.

Comments

1

I had same problem, then found my imports were wrong: the last one of them was using fileupload from sun, not from commons.fileupload. After I changed them all to commons.fileupload, the error disappeared:

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.servlet.ServletRequestContext;

Comments

1

great answers above, but if you are upgrading to tomcat10 which naming change from javax to jakarta, commons-fileupload as of version 1.4 has not change the naming yet, but you can change to the custom class in tomcat10 instead! (LUCKY ME)

org.apache.commons.fileupload.ProgressListener          to org.apache.tomcat.util.http.fileupload.ProgressListener
org.apache.commons.fileupload.servlet.ServletFileUpload to org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload
org.apache.commons.fileupload.disk.DiskFileItemFactory  to org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory

org.apache.commons.fileupload.FileItem                  to org.apache.tomcat.util.http.fileupload.FileItem

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.