Hi Mark!

> -----Ursprüngliche Nachricht-----
> Von: Mark Foley <mfo...@novatec-inc.com>
> Gesendet: Dienstag, 14. November 2023 18:20
> An: users@tomcat.apache.org
> Betreff: Re: AW: FileUpload class not working with Tomcat 10.1
> 
> On Tue Nov 14 01:46:09 2023 "Thomas Hoffmann (Speed4Trade GmbH)"
> <thomas.hoffm...@speed4trade.com.INVALID> wrote:
> >
> > Hello Mark,
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Mark Foley <mfo...@novatec-inc.com>
> > > Gesendet: Montag, 13. November 2023 23:12
> > > An: users@tomcat.apache.org
> > > Betreff: Re: AW: FileUpload class not working with Tomcat 10.1
> > >
> > > On Mon Nov 13 02:18:49 2023 "Thomas Hoffmann (Speed4Trade GmbH)"
> > > <thomas.hoffm...@speed4trade.com.INVALID> wrote:
> > > > Hello,
> > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Mark Foley <mfo...@novatec-inc.com>
> > > > > Gesendet: Sonntag, 12. November 2023 19:04
> > > > > An: users@tomcat.apache.org
> > > > > Betreff: Re: FileUpload class not working with Tomcat 10.1
> > > > >
> > > > > On Fri Nov 10 15:57:50 2023 Christopher Schultz
> > > > > <ch...@christopherschultz.net> wrote:
> > > > > >
> > > > > > Mark,
> > > > > >
> > > > > > On 11/10/23 12:53, Mark Foley wrote:
> > > > > > > On Fri, 10 Nov 2023 17:11:59 Mark Thomas <ma...@apache.org
> > > wrote:
> > > > > > >>
> > > > > > >> On 10/11/2023 16:49, Mark Foley wrote:
> > > > > > >>> I recently upgraded from Tomcat 10.0.17 to 10.1.13.  ...
> > > > > > >>>
> > > > > > >>> [deleted]
> > > > > >
> > > > > I've put your suggested code in place.
> > > > >
> > > > > <%@ page import="jakarta.servlet.http.Part" %>
> > > > >
> > > > > I replaced your:
> > > > >
> > > > >       throw new IllegalStateException("Expected multi-part");
> > > > >
> > > > > with:
> > > > >
> > > > >     out.println("Expected multi-part");
> > > > >
> > > > > Just to get things compiling OK.  I'll deal with errors later.
> > > > > With that change, it compiled w/o problem.  I then attempted an
> > > > > upload.  The
> > > line:
> > > > >
> > > > >    if(null == contentType ||
> > > > > !contentType.startsWith("multipart/form-data;"))
> > > > > {
> > > > >
> > > > > returned TRUE so it did detect a multipart upload. Yay! That was
> > > > > a relief However
> > > > >
> > > > >    Part fileUpload = request.getPart("param-name");
> > > > >
> > > > > Gave me the error:
> > > > >
> > > > > java.lang.IllegalStateException: Unable to process parts as no
> > > > > multi-part configuration has been provided
> > > > >
> > > > > So, what does it mean that "no multi-part configuration has been
> > > provided"?
> > > > > Is "param-name" something I'm supposed to fill in? I tried
> > > > > substituting the <input type="file"> field name, "taxResults",
> > > > > but that
> > > gave the same error.
> > > >
> > > > The form element must have the attribute enctype="multipart/form-
> > > data".
> > > > Furthermore, the servlet must be annotated by "@MultipartConfig"
> > > >
> > > > I think for jsp files, there is a similar setting in the web.xml.
> > > > This link might help out:
> > > > https://stackoverflow.com/questions/37965890/add-annotation-to-jsp
> > >
> > > Thanks for your reply Thomas.
> > >
> > > I've checked your suggested link and I have no idea where to put all
> > > that <?xml> stuff.  Furthermore, the poster of that issue didn't say
> > > he got it working.
> > >
> > > A respnder to the post said, "Actually every jsp file will be
> > > converted to servlet because tomcat can only address servlet and so
> > > every jsp file is indirectly a servlet and has all the features of
> > > it". I think he is suggesting that the <?xml> code is superfluous, but not
> exlpicitly stated as such.
> > >
> > > I am getting a TRUE return for
> > >
> > >   if(null == contentType ||
> > > !contentType.startsWith("multipart/form-data;"))
> > >
> > > so I think it is recognizing it as "multipart/form-data;".
> > >
> > > Does anyone have an example of a JSP program with
> > > jakarta.servlet.http.Part class?
> > >
> > > I'll search for examples as well, but I really have no idea how to 
> > > proceed.
> > >
> > > --Mark F.
> > >
> >
> > The servlet specification defines the special folder WEB-INF.
> > Within this folder, there is the configuration file named web.xml.
> > Within this xml-File, the application is configured including the servlets.
> > JSP-Files are compiled to servlets, either on-the-fly or during compilation
> time.
> >
> > I would recommend to take a look at some sample applications to get
> familiar with some java web-applications and the web.xml file.
> >
> > It is not only about the jsp-file but also the combination with the
> > application configuration within the web.xml Thus you will need both, jsp-
> file and a corresponding web.xml configuration.
> >
> > Greetings!
> > Thomas
> 
> Thomas, I would LOVE to find some examples on this application! I've spent
> days searching and mostly I've found examples for pre 10.1 Tomcat, including
> numerous examples of the type Christopher Schultz found "horrifying".
> Christopher Schultz's suggested example imported
> "jakarta.servlet.http.Part", but your link example doesn't mention that class
> and instead imports "javax.servlet.annotation.MultipartConfig".
> 
> As I said, an actual working example somewhere would be nice.
> 
> I've used WEB-INF/web.xml for several context definitions, so I am familiar
> with it, but have never configured a servlet in web.xml.
> 
> Anyway, enough griping! I have gotten it partially working thanks to your
> suggested link, and particulary you suggestion to put the servlet info in
> web.xml.  I've put the following in WEB-INF/web.xml:
> 
> <servlet>
>   <servlet-name>uploadfile</servlet-name>
>     <jsp-file>/schDistImportResultsX.jsp</jsp-file>
>     <multipart-config>
>       <location>/tmp</location>
>       <max-file-size>20848820</max-file-size>
>       <max-request-size>418018841</max-request-size>
>       <file-size-threshold>1048576</file-size-threshold>
>     </multipart-config>
> </servlet>
> <servlet-mapping>
>   <servlet-name>uploadfile</servlet-name>
>   <url-pattern>/schDistImportResultsX.jsp</url-pattern>
> </servlet-mapping>
> 
> I've only changed the <jsp-file> and <url-pattern> tags above. The others are
> as monkey-typed from your link example. I'll research the other parameters
> later.
> 
> My jsp code is now:
> 
> <%@ page import="javax.servlet.annotation.MultipartConfig.*" %>
> 
> if((contentType != null) && contentType.startsWith("multipart/form-data;"))
> {
>     InputStream inp = null;
>     DataInputStream ins = null;
> 
>     Part fileUpload = request.getPart("taxResults");
> 
>     if(fileUpload != null)
>     {
>         inp = fileUpload.getInputStream();
>         ins = new DataInputStream(inp);
>     }
> 
> while ((inp != null) && (ins.available() != 0)) {
>     String  transaction = ins.readLine();
>     out.println("<br/>" + transaction); }
> 
> ins.close();
> inp.close();
> 
> This actually worked!!!! I will experiment with it more and may be back with
> more questions (e.g. do I really need the web.xml? Could I not do:
> "inp = fileUpload.getInputStream(mypath);"). But ... maybe later.
> 
> Vielen Dank!!! --Mark
> 

Since Tomcat 10 and later the javax package was moved to Jakarta package.
So, jakarta.servlet.annotation.MultipartConfig should be the right one.

I don't know why javax works in your case with Tomcat 10.1.

You need the web.xml because you need to annotate the servlet to support 
Multipart.

Since you have a working example, it should be easier for you to experiment and 
see when something stops working.

Greetings,
Thomas

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

Reply via email to