Hello Lauri, > -----Ursprüngliche Nachricht----- > Von: Lauri <dbam...@hotmail.com> > Gesendet: Freitag, 2. Juni 2023 08:58 > An: Tomcat Users List <users@tomcat.apache.org> > Betreff: 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 > --- > <web-app xmlns="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"> > </web-app> > --- > > -- index.html > --- > <!DOCTYPE html> > <html> > <head> > <meta charset="UTF-8"> > <title>Upload Text File</title> > </head> > <body> > <h1>Upload File</h1> > <form action="upload.jsp" method="post" enctype="multipart/form- > data"> > <input type="file" name="file" /> > <input type="submit" value="Upload" /> > </form> > </body> > </html> > --- > > -- 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.
The @MultipartConfig must be used in the servlet. Here are examples: https://stackoverflow.com/questions/19145489/multipartconfig-override-in-web-xml Multipart-Upload with the mentioned methods can't be done with JSP-Files solely as far as I can see. Only Servlets can be annotated or declared with MultipartConfig I suggest to read some pages about servlets and also take a look at try-with-ressource. Your topic is more about servlet and jsp programming and less about tomcat. > 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 <ma...@apache.org> > Sent: Thursday, June 1, 2023 11:29 AM > To: users@tomcat.apache.org <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 +0000 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 "<jsp-file>" > > Mark > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org