1) Summary of the problem: >From Tomcat 10 and onwards there has been a move from Java EE to Jakarta EE as >part of the transfer of Java EE to the Eclipse Foundation, the primary package >for all implemented APIs has changed from javax.* to jakarta.*.
I have a JSP page deployed in Tomcat 10 that is intended to upload a file from the desktop (Windows 10) to the server where Tomcat 10 is running (OEL 8). I am unable to upload an image, and I get this error: - org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: [24] in the jsp file: [/index.jsp] The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from required type org.apache.commons.fileupload.servlet.ServletFileUpload 21: ServletFileUpload upload = new ServletFileUpload(factory); 22: 23: // Parse the request 24: List<FileItem> items = upload.parseRequest(request); 25: 26: // Process the uploaded items 27: Iterator<FileItem> iter = items.iterator(); - My application name: TESTS I have these libraries for the TESTS application: /u01/tomcat/base/middleware/tomcat10/webapps/TESTS/WEB-INF/lib: commons-fileupload-1.5-test-sources.jar commons-fileupload-1.5-tests.jar commons-fileupload-1.5-sources.jar commons-fileupload-1.5-javadoc.jar commons-fileupload-1.5.jar I have in my Tomcat 10 this library: /u01/tomcat/base/middleware/tomcat10/lib: -rw-r--r--. 1 tomcat tomcat 365905 Apr 25 12:16 servlet-api.jar 2) The deployed JSP page: - <%@ page import="org.apache.commons.fileupload.*" %> <%@ page import="org.apache.commons.fileupload.disk.*" %> <%@ page import="org.apache.commons.fileupload.servlet.*" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="jakarta.servlet.*" %> <%@ page import="jakarta.servlet.http.*" %> <%@ page import="jakarta.sql.*" %> <%@ page import="java.sql.*" %> <%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %> <%@ page import="org.apache.commons.fileupload.FileItemFactory" %> <% // Set the upload directory String uploadDir = "/tmp/"; // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List<FileItem> items = upload.parseRequest(request); // Process the uploaded items Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem item = iter.next(); // If the item is a file, save it to the upload directory if (!item.isFormField()) { String fileName = new File(item.getName()).getName(); String filePath = uploadDir + fileName; File uploadedFile = new File(filePath); item.write(uploadedFile); } } %> <html> <head> <title>File Upload Example</title> </head> <body> <h1>File Upload Example</h1> <form method="post" enctype="multipart/form-data"> <input type="file" name="file" /> <br /> <input type="submit" value="Upload" /> </form> </body> </html> - I have found that it looks like: https://www.linuxquestions.org/questions/linux-server-73/fileupload-class-not-working-with-tomcat-10-a-4175710078/ But in my situation, it seems to be a different problem. Does someone know if this is related to a bug ? Do I use the correct servlet-api jar package ? Do Tomcat 10 need to be specifically configured for using servlet-api and jakarta EE packages ? Does someone know what can be the problem ? Thanks by advance for any tip(s) and/or suggestion(s).