On 02/06/2023 08:20, Thomas Hoffmann (Speed4Trade GmbH) wrote:
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.

That is not correct. You CAN use multi-part upload with JSP files. Rather than using the annotation, you have to define the upload in web.xml. See an earlier post from me in this thread for some links to some examples.

Mark

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

Reply via email to