Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:58:44+00:00 2026-06-15T12:58:44+00:00

I’ve written the method below that is called by my doPost method to parse

  • 0

I’ve written the method below that is called by my doPost method to parse multipart/form-data given in the request. It all works great, I just don’t really understand what is going on. If anyone could break down the three lines in my try I would really appreciate it. I’ve read through the Apache Commons File Upload documentation but it’s just not making sense to me and I hate writing code that I do not fully understand. In particular, I would like to know what is actually happening when the factory and upload objects are created.

public static List<FileItem> parseFormRequest(HttpServletRequest request)
{
    List<FileItem> items = null;

    try 
    {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        items = upload.parseRequest(request);
    } 
    catch (FileUploadException error) 
    {
        System.out.println("UploadFileServlet - Error With File Parsing - " + error.getMessage());
    }

    return items;
}

BONUS HELP!

I also get a warning under upload.parseRequest(request) that says Type safety: The expression of type List needs unchecked conversion to conform to List<FileItem>. If anyone could explain this too that would really help me get what I’ve done. Thanks

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:58:46+00:00Added an answer on June 15, 2026 at 12:58 pm

    The factory is just a helper, i’ll explain later. The main work is done by the ServletFileUpload.

    ServletFileUpload will scan through all the uploaded files (using an Iterator which parses the MIME stuff and knows how to deal with the boundary markers, content length etc.).

    For each uploaded file, the parse method asks the FileItemFactory to create a local representation for the uploaded file and then copies the contents from memory (e.g. from the HTTP POST request, which is held in memory) to the actual file on disk.

    Simplified, the procedure is as follows:

    • Get next uploaded file
    • Ask factory for a local file (“FileItem”)
    • Copy content from in-memory (from HttpServletRequest) to local file (a java.io.File in case of a DiskFileItemFactory)
    • Loop until end of HTTP request is reached

    See the sources of the following classes for details

    • org.apache.commons.fileupload.FileUploadBase.parseRequest(RequestContext)
    • org.apache.commons.fileupload.FileUploadBase.FileItemIteratorImpl.FileItemStreamImpl

    This design allows to switch to another storage facility for files, for example:
    You could replace the DiskFileItemFactory with your own DatabaseFileItemFactory, so the uploaded files get stored in a database instead of a local file on the server. The code changes would only affect a single line and the rest of commons-fileupload can be use as-is (e.g. the parsing of the HTTP request, the iterating over the uploaded
    files etc.)

    For the second question: commons-fileupload seems to be Java 1.4 compatible, so the return type of parseRequest()
    is actually an un-typed java.util.List – it’s missing the declaration that the list only contains FileItem objects (e.g. java.util.List<FileItem>).
    Since you declared your variable items to be of type List<FileItem>, the Java compiler warns you about this mismatch.

    In this case, you did it correctly and you may ignore the warning by adding the following:

    @SuppressWarnings( "unchecked" )
    public static List<FileItem> parseFormRequest(HttpServletRequest request)
    {
       ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.