You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Lauri <db...@hotmail.com> on 2023/05/30 06:17:45 UTC

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 <ma...@apache.org>
Sent: Monday, May 29, 2023 5:44 PM
To: users@tomcat.apache.org <us...@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.

<snip />

> 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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


AW: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by "Thomas Hoffmann (Speed4Trade GmbH)" <Th...@speed4trade.com.INVALID>.
Hello,

> -----Ursprüngliche Nachricht-----
> Von: Torsten Krah <kr...@gmail.com>
> 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 +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.
> 
> 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

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Lauri,

On 6/10/23 03:18, Lauri wrote:
> 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.

Tomcat 10 is very stable, and will likely behave the same as Tomcat 11 
will. The problem is that you are fighting against the API-switchover 
from Java EE to Jakarta EE which is confusing to everybody. The good 
news is that Tomcat supports that switchover in a very elegant fashion.

-chris

> From: Christopher Schultz <ch...@christopherschultz.net>
> Sent: Friday, June 2, 2023 4:45 PM
> To: users@tomcat.apache.org <us...@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
>> ---
>> <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"
> 
> 
> 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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 

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


Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Lauri <db...@hotmail.com>.
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 <ch...@christopherschultz.net>
Sent: Friday, June 2, 2023 4:45 PM
To: users@tomcat.apache.org <us...@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
> ---
> <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"


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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Christopher Schultz <ch...@christopherschultz.net>.
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
> ---
> <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"


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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


AW: AW: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by "Thomas Hoffmann (Speed4Trade GmbH)" <Th...@speed4trade.com.INVALID>.
Hello Mark,

> -----Ursprüngliche Nachricht-----
> Von: Mark Thomas <ma...@apache.org>
> Gesendet: Freitag, 2. Juni 2023 14:18
> An: users@tomcat.apache.org
> Betreff: Re: AW: Re-Cannot upload an image file from a deployed JSP page in
> Tomcat 10
> 
> On 02/06/2023 08:20, Thomas Hoffmann (Speed4Trade GmbH) wrote:
> > Hello Lauri,
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: Lauri <db...@hotmail.com>
> >> Gesendet: Freitag, 2. Juni 2023 08:58
> >> An: Tomcat Users List <us...@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.

Thanks for the correction!
Now I understand the example in your link.

The trick is:
           <multipart-config>
               <location>/temp</location>
           ....

> Mark
> 
> ---------------------------------------------------------------------


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


Re: AW: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Mark Thomas <ma...@apache.org>.
On 02/06/2023 08:20, Thomas Hoffmann (Speed4Trade GmbH) wrote:
> Hello Lauri,
> 
>> -----Ursprüngliche Nachricht-----
>> Von: Lauri <db...@hotmail.com>
>> Gesendet: Freitag, 2. Juni 2023 08:58
>> An: Tomcat Users List <us...@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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


AW: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by "Thomas Hoffmann (Speed4Trade GmbH)" <Th...@speed4trade.com.INVALID>.
Hello Lauri,

> -----Ursprüngliche Nachricht-----
> Von: Lauri <db...@hotmail.com>
> Gesendet: Freitag, 2. Juni 2023 08:58
> An: Tomcat Users List <us...@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 <us...@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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


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


Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Lauri <db...@hotmail.com>.
@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.

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 <us...@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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Mark Thomas <ma...@apache.org>.
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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Torsten Krah <kr...@gmail.com>.
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.

kind regards

Torsten

-- 


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


Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Lauri <db...@hotmail.com>.
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 <kr...@gmail.com>
Sent: Wednesday, May 31, 2023 11:53 AM
To: users@tomcat.apache.org <us...@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 +0000 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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Torsten Krah <kr...@gmail.com>.
Am Mittwoch, dem 31.05.2023 um 09:42 +0000 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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Lauri <db...@hotmail.com>.
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 <kr...@gmail.com>
Sent: Wednesday, May 31, 2023 11:25 AM
To: users@tomcat.apache.org <us...@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 +0000 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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Torsten Krah <kr...@gmail.com>.
Am Mittwoch, dem 31.05.2023 um 09:14 +0000 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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Lauri <db...@hotmail.com>.
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 <ma...@apache.org>
Sent: Tuesday, May 30, 2023 9:22 AM
To: users@tomcat.apache.org <us...@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 <ma...@apache.org>
> Sent: Monday, May 29, 2023 5:44 PM
> To: users@tomcat.apache.org <us...@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.
>
> <snip />
>
>> 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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

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


Re: Re-Cannot upload an image file from a deployed JSP page in Tomcat 10

Posted by Mark Thomas <ma...@apache.org>.
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 <ma...@apache.org>
> Sent: Monday, May 29, 2023 5:44 PM
> To: users@tomcat.apache.org <us...@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.
> 
> <snip />
> 
>> 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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 

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