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 648525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:50:33+00:00 2026-05-13T21:50:33+00:00

I am trying to upload a file using commons-fileupload-1.1.1.jar file (I know it is

  • 0

I am trying to upload a file using commons-fileupload-1.1.1.jar file (I know it is not the latest version but it comes with struts 1.3.10 so I am using the same).

Now the problem is when I parse the request (HttpServletRequest) to get a List of FileItems, I am getting an empty list.

        DiskFileItemFactory factory = new DiskFileItemFactory();

        File tempDir = new File("/fileUploadDirectory");
        tempDir.mkdir();

        // Set factory constraints
        factory.setSizeThreshold(10000);
        factory.setRepository(tempDir);

        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);

        // Set overall request size constraint
        upload.setSizeMax(10000);

        // Parse the request
        List items = upload.parseRequest(request);
        System.out.println(items);

        System.out.println(request.getContentLength());

        // Process the uploaded items
        Iterator<FileItem> iter = items.iterator();
        while (iter.hasNext()) {
            FileItem item = iter.next();
            if (item.isFormField()) {
                System.out.println("File is a FormField");
            } else {
                System.out.println("File is a File");
            }
        } 

Q1. Why I am getting an empty list?

When I am printing the size of the request by request.getContentLength() (as shown above in the code), I get some numerical data (1536) which I think is showing the length of the file. If it is showing the length of the file, then why I am not getting list of FileItems?

Note: I am using it with Struts 1.3.10 with ActionForm. Is is creating any problem.

Note: I am also not getting any exception while parsing the request.

  • 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-05-13T21:50:33+00:00Added an answer on May 13, 2026 at 9:50 pm

    If the list is empty, then the request was most likely not send as multipart/form-data. Ensure that the request method is set to post and that encoding type is set to multipart/form-data:

    <form method="post" enctype="multipart/form-data">
    

    (just substitute the HTML <form> element with the Struts equivalent, which is likely <html:form>)

    That said, why don’t you make use of the Struts builtin file upload component? Googling learns me that there’s a <html:file> component which needs to be tied with a org.apache.struts.upload.FormFile property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying to upload image file using perl cgi-application. Not sure what
I'm trying to upload a file using JavaFX using the HttpRequest. For this purpose
I am trying to upload files using Spring CommonsMultipartResolver however the controller is not
I'm trying to upload a file using an Ant task. If I use Ant
I'm trying to upload a file using AJAX, process data in the file and
I'm trying to upload a file using PHP. My HTML page with the form
I trying to upload a zip file. In my project i am using DWR
I am trying to upload file to google sites and am obtaining the stream
I'm using Apache common fileupload library with Netbeans 6.8 + Glassfish.I'm trying to change
I am using Codeigniter and I am trying to upload multiple files into 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.