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
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
AW: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10
Hello, > -Ursprüngliche Nachricht- > Von: Torsten Krah > Gesendet: Donnerstag, 1. Juni 2023 11:18 > An: users@tomcat.apache.org > Betreff: Re: Re-Cannot upload an image file from a deployed JSP page in > Tomcat 10 > > 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. > > kind regards > > Torsten > In general it is good practice to separate logic and layout. JSP are usually for providing the view / layout. Logic / java code should be used in servlets and other java classes (e.g. models). So it is recommended anyway to move java code from JSP to java classes. See https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Greetings, Thomas
Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10
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. 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