Ho Thomas,

I still do not understand everything.

I understood the following:

1)
>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.*.

2)
I understood from your post that the package commons-fileupload has 
dependencies to the old javax package.

3)
I can remove the commons-fileupload-* jar files from my application (because of 
what has been said above):
/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

Can you tell me what I should modify on the JSP file that I have posted if I 
want to upload a binary file (image,...) ?
What modules should I use if these are wrong ?

<%@ page import="org.apache.commons.fileupload.*" %> => TO REMOVE
<%@ page import="org.apache.commons.fileupload.disk.*" %> => TO REMOVE
<%@ page import="org.apache.commons.fileupload.servlet.*" %> => TO REMOVE
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="jakarta.servlet.*" %>
<%@ page import="jakarta.servlet.http.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="jakarta.sql.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %> => 
TO REMOVE
<%@ page import="org.apache.commons.fileupload.FileItemFactory" %> => TO REMOVE

Kind Regards,

Lauri

________________________________
From: Thomas Hoffmann (Speed4Trade GmbH) 
<thomas.hoffm...@speed4trade.com.INVALID>
Sent: Tuesday, May 30, 2023 8:24 AM
To: Tomcat Users List <users@tomcat.apache.org>
Subject: AW: Re-Cannot upload an image file from a deployed JSP page in Tomcat 
10

Hello Lauri,

> -----Ursprüngliche Nachricht-----
> Von: Lauri <dbam...@hotmail.com>
> Gesendet: Dienstag, 30. Mai 2023 08:20
> An: Tomcat Users List <users@tomcat.apache.org>
> Betreff: Re-Cannot upload an image file from a deployed JSP page in Tomcat
> 10
>
> 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-cl
> > ass- 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
>


The package commons-fileupload has dependencies to the old javax package:
https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload/1.5

It is not ready for Jakarta EE and you don't need this package for file uploads 
because
you can use the default servlet methods to retrieve the file (this was the link 
I sent).

Greetings,
Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to