Hi Thomas, I get returned "Page no found" when I navigate through: https://www.linuxquestions.org/questions/linux-server-73/fileupload-class-
I don't understand the relation between the code in my JSP page and the link you provided me: https://docs.oracle.com/javaee/6/tutorial/doc/gmhba.html What do you mean exactly ? Thanks by advance for any indications. Kind Regards, Lauri ________________________________ From: Thomas Hoffmann (Speed4Trade GmbH) <thomas.hoffm...@speed4trade.com.INVALID> Sent: Monday, May 29, 2023 8:39 PM To: Tomcat Users List <users@tomcat.apache.org> Subject: AW: Cannot upload an image file from a deployed JSP page in Tomcat 10 Hallo Lauri, > -----Ursprüngliche Nachricht----- > Von: Lauri <dbam...@hotmail.com> > Gesendet: Montag, 29. Mai 2023 11:36 > An: users@tomcat.apache.org > Betreff: Cannot upload an image file from a deployed JSP page in Tomcat 10 > > 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). I had the same issue because I used internal Tomcat classes. In the past the servlet specification didn't have methods to deal with multipart uploads. Since Servlet 3.0 there are methods for retrieving the uploads: https://docs.oracle.com/javaee/6/tutorial/doc/gmhba.html I replace the ServletFileUpload and used standard methods like getParts(). This worked for me. Greetings, Thomas --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org