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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:42:47+00:00 2026-06-05T05:42:47+00:00

well I’m trying to upload a file to my servlet from the web interface.

  • 0

well I’m trying to upload a file to my servlet from the web interface. I’ve been using Apache Commons FileUpload by following a tutorial and integrating it into my servlet. Somehow I can’t manage to get the file uploaded.

Here’s my form in the web page:

<form class="well" action="GenTreeUploader" method="post" enctype="multipart/form-data">
        <label>Choose your file:</label>
        <center><input type="file" class="input-xlarge" name="wordfile"></center><br>
        <center><span class="help-block">Note: after clicking "Upload file!" all of the data contained in the file will be uploaded to the database</span></center><br>
        <center><input class="btn btn-primary" type="submit" value="Upload file!"></center>  
        <input type="text" name="tester" value="xoxoxo" />
        <input type="hidden" name="action" value="startUpload" />
    </form>

Then here’s my code part of the servlet that should handle the file upload from the request:

public void artiUpload(HttpServletRequest request, HttpServletResponse response, HtmlWriter writer) throws ServletException, IOException {
    System.out.println("I'm in upload");
    PrintWriter out = response.getWriter();
    // Check that we have a file upload request
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    // Create a factory for disk-based file items

    // Create a factory for disk-based file items
    DiskFileItemFactory factory = new DiskFileItemFactory();

    // Set factory constraints
    factory.setSizeThreshold(maxMemSize);
    factory.setRepository(new File(htmlPath.toString()));
    System.out.println("File path: " + htmlPath.toString());

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

    // Set overall request size constraint
    upload.setSizeMax(maxFileSize);
    System.out.println("Max file size: " + maxFileSize);
    System.out.println("Max file size in memory: " + maxMemSize);
    List items = null;
    try {
        // Parse the request
        items = upload.parseRequest(request);
        System.out.println("Items found: " + items.size());
        out.write(writer.printCenter("File uploading done"));
    } catch (FileUploadException ex) {
        Logger.getLogger(GenTreeUploader.class.getName()).log(Level.SEVERE, null, ex);
        out.write(writer.printCenter("File uploading failed"));
    }
}

And here is the Tomcat server log I get from this servlet method:

I'm in upload
File path: D:\Dropbox\StudiesNew\NetbeansProjects\GenTreeUploader\build\web\WEB-INF\classes\Html
Max file size: 10485760
Max file size in memory: 2097152
Items found: 0

Well I’m also getting some parameters from the request by using:
action = request.getParameter(actionText);

Works fine with normal parameters, but the file doesn’t get uploaded. I believe after parsing the list should have one item in this case, it shows 0…

Can anyone help? Thanks.

The full log is this?

 Using CATALINA_BASE:   "C:\Users\Arturas\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base"
Using CATALINA_HOME:   "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22"
Using CATALINA_TMPDIR: "C:\Users\Arturas\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.7.0_03"
Using CLASSPATH:       "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22\bin\tomcat-juli.jar"
Bir 05, 2012 2:45:06 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.7.0_03\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\MATLAB\R2010b\runtime\win64;C:\Program Files\MATLAB\R2010b\bin;.
Bir 05, 2012 2:45:07 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8084"]
Bir 05, 2012 2:45:07 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Bir 05, 2012 2:45:07 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 865 ms
Bir 05, 2012 2:45:07 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Bir 05, 2012 2:45:07 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.22
Bir 05, 2012 2:45:07 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor GenTreeUploader.xml from C:\Users\Arturas\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Bir 05, 2012 2:45:08 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml from C:\Users\Arturas\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Bir 05, 2012 2:45:08 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor mrweb.xml from C:\Users\Arturas\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Bir 05, 2012 2:45:08 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor ROOT.xml from C:\Users\Arturas\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Bir 05, 2012 2:45:08 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8084"]
Bir 05, 2012 2:45:08 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Bir 05, 2012 2:45:08 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1396 ms
I'm in upload
File path: D:\Dropbox\StudiesNew\NetbeansProjects\GenTreeUploader\build\web\WEB-INF\classes\Html
Max file size: 10485760
Max file size in memory: 2097152
Items found: 0
  • 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-05T05:42:49+00:00Added an answer on June 5, 2026 at 5:42 am

    It will fail that way when the request body has already been parsed beforehand by calling getParameter(), getReader() or getInputStream() methods on the request inside the doPost() method of the very same servlet or inside the doFilter() method of one of the servlet filters which also runs on the same request. Another possible cause is that you’re nesting HTML <form> elements, but the behaviour is browser dependent.

    By the way, the HTML <center> element is deprecated since 1998. Get rid of it and use CSS instead.


    Update: your update confirms that you’re calling getParameter() on the request. You should not do that when it’s a multipart/form-data request. You should instead use the very same Apache Commons FileUpload API to collect normal form fields. See also How to upload files to server using JSP/Servlet?

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

Sidebar

Related Questions

well I'm trying to create a great playlist of music, only using a sigle
Well, in fact I would like to do the following in an interface: public
Well...I feel absolutely stupid. Here's why: I have been using some library functions I
well, I am trying to include a header file in my project, while the
Well, i'm designing a small affiliate system using PHP and Neo4J in order to
Well, i have the following need: create 3 dropdownlist with dependencies. My table in
well i have used an html file like these in iframe <iframe src=sample.html></iframe> is
I am trying to render a haml file in a javascript response like so:
Well I have been thinking about this for a while, ever since I was
Well, I'm trying to reuse a portion of C# code. It's an abstract class

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.