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.  When I previously 
> > upgraded
> > from 9.0.41 to 10.0.17 (back in 2/22) the FileUpload class broke. I fixed 
> > that
> > thanks to postings on stackoverflow, but now that I've
> > upgraded to 10.1.13 it is broken again! Here's the error I get:
> > 
> > An error occurred at line: [40] in the jsp file: [/schDistImportResults.jsp]
> > The method isMultipartContent(ServletRequestContext) is undefined for the 
> > type FileUpload
>
> Tomcat's internal fork of Commons FileUpload isn't intended for 
> applications to use. It is not a full fork - just a limited subset of 
> the functionality Tomcat needs to implement the Servley upload API.
>
> If you want to use Commons File Upload, add the JAR to your web 
> application and use it.
>
> Alternatively, if you want to use the Servlet upload API then use that.
>
> If the javax.sevlet -> jakarta.servlet transition means you can't use 
> your preferred version of Commons File Upload in Tomcat 10.1.x (very 
> likely) then run your preferred version of Commons File Upload through 
> Tomcat's migration tool for Jakarta EE and use the converted version of 
> Commons File Upload in your web application.
>
> Depending on Tomcat internals is very likely to lead to breakage.
>
> Mark

Thanks for your quick reply. Whatever I've been using keeps breaking. I had it
working in 9.0.14 and earlier, then it broke with 10.0.17 and I fixed that, now
it's broken again with 10.1.13. So, my "prefered" solution is whatever is
recommended and is likely to continue to be supported without breaking in future
Tomcats.

What do you recommend? And do you have a quickie template somewhere which shows
the basic include(s) and method I need? I really don't do anything very fancy.
My current "basic" implementation is:

<%@ page import="org.apache.tomcat.util.http.fileupload.*,
    org.apache.tomcat.util.http.fileupload.disk.*,
    org.apache.tomcat.util.http.fileupload.servlet.*,
    org.apache.commons.io.*" %>

DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(new ServletRequestContext(request));
Iterator iter = items.iterator();
FileItem item = null;

while (iter.hasNext())
{
    item = (FileItem) iter.next();

    resultsFile = new File(getServletContext().getRealPath("") + 
"/tmp/schTaxResults.txt");

    try { item.write(resultsFile); }
        catch ( Exception e) { out.println("Exception: " + e); }
}    

If you could tell me what the officially prefered Apache Tomcat FileUpload
mechanism is, and what the correct jar and functions are to accomplish the 
above, I'd be
very grateful!

Thanks --Mark

> > [deleted]

> > I've checked the RELEASE-NOTES, FAQ and searched the web.  I've checked the
> > UploadFile class (no clue) and looked for examples, but none resembled my 
> > app.
> > I tried reverting back to the program version I had with 9.0.41, but that 
> > didn't
> > work.
> > 
> > Here is all I changed in the program between Tomcat versions 9.0.41 and 
> > 10.0.17 (which worked):
> > Code:
> > [deleted]
> > 
> > I have quite a few programs that use the FileUpload methods. Does anyone 
> > know how to fix this latest breakage?
> > 
> > Thanks --Mark
> > 

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

Reply via email to