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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:08:01+00:00 2026-05-30T23:08:01+00:00

I trying to implement fileUpload , But I get an error described below. i

  • 0

I trying to implement fileUpload , But I get an error described below.

i Checked this document , BUT I DIDNT UNDERSTOOD THE PROBLEM IN MY CODE;
the problem is in Line 46 which i have marked in code.

Someone Plz help me with solution.

     private static final String UPLOAD_DIRECTORY = "d:\\";
     public void doPost(HttpServletRequest request,HttpServletResponse response){
         ServletFileUpload upload = new ServletFileUpload();

    if(ServletFileUpload.isMultipartContent(request)){


        FileItemFactory factory = new DiskFileItemFactory();

        ServletFileUpload servletFileUpload = new ServletFileUpload(factory);

        try {
Line 46---> error      List<FileItem> items = upload.parseRequest(request);

             for(FileItem item : items){

                  if( item.isFormField())continue;

                  String fileName = item.getName();
                  if (fileName != null) {
                      fileName = FilenameUtils.getName(fileName);
                                          }
                  File uploadedFile = new File(UPLOAD_DIRECTORY, fileName);
                  if (uploadedFile.createNewFile()) {
                      item.write(uploadedFile);
                      response.setStatus(HttpServletResponse.SC_CREATED);
                      response.getWriter().print("The file was created successfully.");
                      response.flushBuffer();
                  }else{
                      throw new IOException("The file already exists in repository.");
                  }

             }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();


        } 
    }else{
        try {
            response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,"Request contents type is not supported by the servlet" );
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

     }

Error generated:

   java.lang.NullPointerException: No FileItemFactory has been set.
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:354)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
    at com.server.FileUpload.doPost(FileUpload.java:46)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  • 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-30T23:08:03+00:00Added an answer on May 30, 2026 at 11:08 pm

    At a guess, it’s because you’re using upload, which wasn’t initialized with a DiskFileItemFactory, instead of servletFileUpload, which was.

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

Sidebar

Related Questions

Trying to implement this gallery on my website. http://coffeescripter.com/code/ad-gallery/ It is noted in the
Trying to implement the new FP 10.1 Global error handler into my projects but
im trying to implement a custom error page, what i want to be able
Found a really nice code for Accordion nav and am trying implement on our
Trying to implement simple error handling without adding buku try / except statements to
Trying to implement the decorator pattern in C# from the code in the Head
I'm trying to implement file upload functionality in the iPhone app. Server code is
SetFocus I'm trying implement the above Se Focus code in a Class Library that
I'm trying to implement this method of making a nice form upload: www.kavoir.com/2009/02/styling-file-upload-select-input-control-input-typefile.html/ which
I am trying to implement a File Uploader until the PF 3.X FileUpload becomes

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.