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 items = upload.parseRequest(request); 25: 26: // Process the uploaded items 27: Iterator 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 items = upload.parseRequest(request); // Process the uploaded items Iterator 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); } } %> File Upload Example File Upload Example - 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).
Re-Cannot upload an image file from a deployed JSP page in Tomcat 10
Hi Mark, If I understand well: a) I should remove the commons*.jar files from my /u01/tomcat/base/middleware/tomcat10/webapps/TESTS/WEB-INF/lib. b) I do not need to have a specific configuration for Tomcat 10 to use servlet-api and jakarta EE packages. I still do not understand the following: c) Do I use the correct servlet-api jar package ? You answered: If you are using Tomcat 10, you need to use the Jakarta EE package names. You can't use the Java EE package names. You can't use any library that uses the Java EE package names. But the servlet-api is already included in the Tomcat 10 lib. What's wrong with this ? d) Does someone know what can be the problem ? You answered: See above. You are trying to use a Java EE library with Jakarta EE. I use these modules in the 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" %> What's wrong with this ? e) Option 1, 2, 3 The JSP page has not been migrated from Tomcat X to Tomcat 10. It has been directly deployed in Tomcat 10. What is wrong in the code of my JSP page ? Thanks by advance for any indications. Kind Regards, Lauri ____ From: Mark Thomas Sent: Monday, May 29, 2023 5:44 PM To: users@tomcat.apache.org Subject: Re: Cannot upload an image file from a deployed JSP page in Tomcat 10 On 29/05/2023 10:36, Lauri wrote: > 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.*. Note the above. > 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 You should not have any of the above in your web application. > commons-fileupload-1.5.jar That library uses the Java EE APIs so it won't work with Tomcat 10 as you have discovered. > Does someone know if this is related to a bug ? No. There is no bug. > Do I use the correct servlet-api jar package ? If you are using Tomcat 10, you need to use the Jakarta EE package names. You can't use the Java EE package names. You can't use any library that uses the Java EE package names. > Do Tomcat 10 need to be specifically configured for using servlet-api and > jakarta EE packages ? No. > Does someone know what can be the problem ? See above. You are trying to use a Java EE library with Jakarta EE. > Thanks by advance for any tip(s) and/or suggestion(s). Option 1. Write your web application using the Jakarta EE APIs. Use the Tomcat migration tool for Jakarta EE to convert commons-fileupload-1.5.jar from from Java EE to Jakarta EE (and any other libraries using the Java EE APIs). Deploy your web application with the converted JARs. Option 2. Write your web application using the Java EE APIs and then deploy it to webapps-javaee rather than webapps and Tomcat will use the migration tool to convert your web application for you. Option 3. Write your web application using the Java EE APIs and convert it to Jkarata EE using the migration tool. Once converted, deploy it to the webapps directory. Note: If you use any deprecated Java EE APIs you may still see failures after conversion as Jakarta EE 10 most of the deprecated APIs. Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
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) Sent: Monday, May 29, 2023 8:39 PM To: Tomcat Users List Subject: AW: Cannot upload an image file from a deployed JSP page in Tomcat 10 Hallo Lauri, > -Ursprüngliche Nachricht- > Von: Lauri > 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 items = upload.parseRequest(request); > 25: > 26: // Process the uploaded items > 27: Iterator 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 items = upload.parseRequest(request); > > // Process the uploaded items > Iterator 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); > } > } > %> > > > File Upload Example > > > File Upload Example > > > > > > > > - > > 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
Re-Cannot upload an image file from a deployed JSP page in Tomcat 10
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) Sent: Tuesday, May 30, 2023 8:24 AM To: Tomcat Users List Subject: AW: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10 Hello Lauri, > -Ursprüngliche Nachricht- > Von: Lauri > Gesendet: Dienstag, 30. Mai 2023 08:20 > An: Tomcat Users List > 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) > > Sent: Monday, May 29, 2023 8:39 PM > To: Tomcat Users List > Subject: AW: Cannot upload an image file from a deployed JSP page in > Tomcat 10 > > Hallo Lauri, > > > -Ursprüngliche Nachricht- > > Von: Lauri > > 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 items = upload.parseRequest(request); > > 25: > > 26: // Process the uploaded items > > 27: Iterator 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: > &
Re-Cannot upload an image file from a deployed JSP page in Tomcat 10
Ho Mark, 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) The package commons-fileupload has dependencies to the old javax package. 3) I can remove the commons-fileupload-* jar files from my 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 4) I do not need a specific configuration for Tomcat 10. 5) I can use the already available servlet-api jar package from Tomcat 10. I can go for Option 2. So, I guess I need to re-write my JSP page as if it was for Java EE for Tomcat 9 (or earlier versions) for instance, correct? You wrote "Write your web application using the Java EE APIs and then deploy it to webapps-javaee rather than webapps and Tomcat will use the migration tool to convert your web application for you". What is webapps-javaee ? How can I use it if I have a JSP page for Java EE. Kind Regards, Lauri From: Mark Thomas Sent: Tuesday, May 30, 2023 9:22 AM To: users@tomcat.apache.org Subject: Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10 On 30/05/2023 07:17, Lauri wrote: > Hi Mark, > > If I understand well: > > a) I should remove the commons*.jar files from my > /u01/tomcat/base/middleware/tomcat10/webapps/TESTS/WEB-INF/lib. No. commons-fileupload-1.5.jar (in some form) can stay (see option 1). > b) I do not need to have a specific configuration for Tomcat 10 to use > servlet-api and jakarta EE packages. Correct. > I still do not understand the following: > > c) Do I use the correct servlet-api jar package ? Yes. > You answered: > If you are using Tomcat 10, you need to use the Jakarta EE package > names. You can't use the Java EE package names. You can't use any > library that uses the Java EE package names. > > But the servlet-api is already included in the Tomcat 10 lib. > What's wrong with this ? commons-fileupload-1.5.jar uses the Java EE API. It will not work with Tomcat 10. > I use these modules in the 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" %> > > What's wrong with this ? See above. > e) Option 1, 2, 3 > > The JSP page has not been migrated from Tomcat X to Tomcat 10. > It has been directly deployed in Tomcat 10. > > What is wrong in the code of my JSP page ? > Thanks by advance for any indications. There is nothing wrong with the code in the JSP page but the library you are trying to use (commons-fileupload-1.5.jar) will not work with Tomcat 10. The quickest fix is probably option 1: Use the Tomcat migration tool for Jakarta EE to convert commons-fileupload-1.5.jar from from Java EE to Jakarta EE and then use the converted JAR rather than the original. The best solution is probably the one Thomas pointed out: Option 4: Stop using commons-fileupload-1.5.jar and use the methods provided by the Servlet API to handle file uploads. Mark > > Kind Regards, > > Lauri > > > From: Mark Thomas > Sent: Monday, May 29, 2023 5:44 PM > To: users@tomcat.apache.org > Subject: Re: Cannot upload an image file from a deployed JSP page in Tomcat 10 > > On 29/05/2023 10:36, Lauri wrote: > >> 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.*. > > Note the above. > > > >> 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-ja
Re-Cannot upload an image file from a deployed JSP page in Tomcat 10
Of course, I would prefer to work with Jakarta (that's anyway the trend). But my initial question remains, what should have to modify on my posted JSP page ? Kind Regards, Lauri From: Torsten Krah Sent: Wednesday, May 31, 2023 11:25 AM To: users@tomcat.apache.org Subject: Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10 Am Mittwoch, dem 31.05.2023 um 09:14 + schrieb Lauri: > So, I guess I need to re-write my JSP page as if it was for Java EE > for Tomcat 9 (or earlier versions) for instance, correct? Why would you want to do that? Just rewrite it to work with the jakarta api and it will work with tomcat 10. kind regards Torsten -- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re-Cannot upload an image file from a deployed JSP page in Tomcat 10
I don't ask to fix the code. I wish to understand what is wrong how it can be possibly solved keeping the format of a JSP page. You mention a servlet part, but I do not use a servlet. All the code is contained in the JSP page. From: Torsten Krah Sent: Wednesday, May 31, 2023 11:53 AM To: users@tomcat.apache.org Subject: Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10 Am Mittwoch, dem 31.05.2023 um 09:42 + schrieb Lauri: > But my initial question remains, what should have to modify on my > posted JSP page ? We already posted you with the docs where you can read about the necessary changes you need to make to your page, it is all written there (just call getParts() or getPart(..) on the servlet request object). You can ask about specific failures again if you have errors etc. but at least I don't fix your code to make it work - you can do that yourself and ask again if something isn't working like expected, after reading the docs we pointed you to and adapting your page. That's my 2 cents about it. kind regards Torsten -- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re-Cannot upload an image file from a deployed JSP page in Tomcat 10
@Thomas: I have made a test using the request.getParts() API, as mentioned here: https://docs.oracle.com/javaee/6/tutorial/doc/glrbb.html The test upload application has been modified as: -- web.xml --- http://xmlns.jcp.org/xml/ns/javaee"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_5_0.xsd"; version="5.0"> --- -- index.html --- Upload Text File Upload File --- -- upload.jsp --- <%@ page import="java.io.*, java.util.*, javax.servlet.*, javax.servlet.http.*" %> <% Part part = request.getPart("file"); if (part != null) { InputStream stream = part.getInputStream(); File file = new File("/tmp/" + part.getSubmittedFileName()); FileOutputStream outputStream = new FileOutputStream(file); byte[] buffer = new byte[4096]; int bytesRead = -1; while ((bytesRead = stream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.close(); stream.close(); } else { out.println("No file uploaded."); } %> --- The @MultipartConfig is defined in the HTML file. When deployed in Tomcat 10, I still get these errors: --- org.apache.jasper.JasperException: An exception occurred processing [/upload.jsp] at line [3] 1: <%@ page import="java.io.*, java.util.*, javax.servlet.*, javax.servlet.http.*" %> 2: <% 3: Part part = request.getPart("file"); 4: if (part != null) { 5: InputStream stream = part.getInputStream(); 6: File file = new File("/tmp/" + part.getSubmittedFileName()); --- @Mark: Refering to: https://stackoverflow.com/questions/37965890/add-annotation-to-jsp I do not upload a (image) file to the database, but on the server (/tmp). Kind Regards From: Mark Thomas Sent: Thursday, June 1, 2023 11:29 AM To: users@tomcat.apache.org Subject: Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10 On 01/06/2023 10:18, Torsten Krah wrote: > Am Donnerstag, dem 01.06.2023 um 08:52 + schrieb Lauri: >>> You mention a servlet part, but I do not use a servlet. >>> All the code is contained in the JSP page. > > You need to divide that code in a JSP and in your upload servlet as you > need to provide the @MultipartConfig on that servlet which handles your > upload. > Without that you will get: > > Unable to process parts as no multi-part configuration has been provided > > as an exception when accessing the request.getParts() API. > > The whole thing is all written there btw: > > https://docs.oracle.com/javaee/6/tutorial/doc/glrbb.html > > I don't know - maybe Mark does - if you can annotate a JSP page, had > never seen it or read about that so my best guess is, you can't do that > and you need to use a servlet + jsp unless you want to overwrite the > JspServlet from Tomcat with a custom one which does have that > annotation and handles the Jsp stuff. You can do this via web.xml. See the following SO question for an example specific to this question: https://stackoverflow.com/questions/37965890/add-annotation-to-jsp For some more general examples: https://github.com/apache/tomcat/blob/main/test/webapp/WEB-INF/web.xml Search for "" Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10
Hi, Thanks for all the tips. It is solved. I managed to create such a working page in Tomcat 9 (without any specific configuration). I just deployed that same page in Tomcat 10(also without any specific configuration), and it works. For the rest, I will wait for Tomcat 11. I guess it will be a more stable version. Kind Regards, Lauri From: Christopher Schultz Sent: Friday, June 2, 2023 4:45 PM To: users@tomcat.apache.org Subject: Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10 Lauri, On 6/2/23 02:58, Lauri wrote: > @Thomas: > > I have made a test using the request.getParts() API, as mentioned here: > https://docs.oracle.com/javaee/6/tutorial/doc/glrbb.html > > The test upload application has been modified as: > > -- web.xml > --- > http://xmlns.jcp.org/xml/ns/javaee"; > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; > xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee > > http://xmlns.jcp.org/xml/ns/javaee/web-app_5_0.xsd"; If you want to use Tomcat 10, these are the wrong XML schema references. You want the Jakarta ones. > <%@ page import="java.io.*, java.util.*, javax.servlet.*, > javax.servlet.http.*" %> If you want to use Tomcat 10, these are the wrong packages. You want the Jakarta ones. -chris - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org