I am migrating Webapps from a Tomcat 9
to a Tomcat 10
environment.
I am using the Eclipse IDE
.
Below is a part of the code that provokes errors:
import java.util.List;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
[...]
DiskFileItemFactory diskFileItemFactory = null;
ServletFileUpload servletFileUpload = null;
List<FileItem> fileItemsList = null;
diskFileItemFactory = new DiskFileItemFactory();
servletFileUpload = new ServletFileUpload(diskFileItemFactory);
fileItemsList = (List<FileItem>) servletFileUpload.parseRequest(request);
The errors are linked to this last line.
I get the errors:
The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.http.HttpServletRequest. Fix the build path then try building this project
The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from required .class files
As part of this migration, I had to replace javax.servlet
with jakarta.servlet
in the Webapps Java source code and replace the .jars javax.servlet.jsp.jstl-1.2.1.jar
and javax.servlet.jsp.jstl-api-1.2.1.jar
with the jakarta.servlet.jsp.jstl-2.0.0.jar
and jakarta.servlet.jsp.jstl-api-2.0.0.jar
.jars.
Can you help me solve these errors?
====== EDIT ======
Piotr P. Karwasz's answer solves my problem.
But, instead of adding annotations, which doesn't seem to work for me, I added, in the Webapp web.xml
file, for the servlets concerned, the <multipart-config>
element as shown below:
<servlet>
<description></description>
<display-name>FooServlet</display-name>
<servlet-name>FooServlet</servlet-name>
<servlet-class>com.foo.bar.FooServlet</servlet-class>
<multipart-config>
<location>/tmp</location>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
</servlet>
<servlet-mapping>
<servlet-name>FooServlet</servlet-name>
<url-pattern>/do_foo_servlet</url-pattern>
</servlet-mapping>