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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:35:45+00:00 2026-05-28T06:35:45+00:00

I am trying to create a upload form using servlets, and so far i

  • 0

I am trying to create a upload form using servlets, and so far i have the following;

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);

    if (isMultipart) {
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);

        try {
            List items = upload.parseRequest(request);
            Iterator iterator = items.iterator();
            while (iterator.hasNext()) {
                FileItem item = (FileItem) iterator.next();

                if (!item.isFormField()) {
                    String fileName = item.getName();

                    String root = getServletContext().getRealPath("");
                    File path = new File(root + "/uploads");

                    if (!path.exists()) {
                        boolean status = path.mkdirs();

                    }

                    File uploadedFile = new File(path + "/" + fileName);
                    System.out.println(uploadedFile.getAbsolutePath());
                    item.write(uploadedFile);

                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

It seems to upload the files fine, however it always throws a java.io.FileNotFoundException:
Have i done something wrong?

ERROR:

    /Applications/Tomcat/apache-tomcat-6.0.35/wtpwebapps/work/uploads/texsxxdddst.xml
/Applications/Tomcat/apache-tomcat-6.0.35/wtpwebapps/work/uploads
java.io.FileNotFoundException: /Applications/Tomcat/apache-tomcat-6.0.35/wtpwebapps/work/uploads (No such file or directory)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:145)
    at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:426)
    at servlets.uploadServlet.doPost(uploadServlet.java:48)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:680)
  • 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-28T06:35:46+00:00Added an answer on May 28, 2026 at 6:35 am

    My guess is that the directory where you want to write files is write-protected, or that you don’t have the rights to write there. You shouldn’t write these files in this directory anyway, because it will be deleted if you undeploy or redeploy the webapp. Consider that Tomcat’s directory is under Tomcat’s responsibility.

    Choose a directory, outside of Tomcat, where you want to store your uploads, and configure your webapp with a parameter containing this path. Use this parameter in your code to get the path and write the uploaded files.

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

Sidebar

Related Questions

I'm trying to create a simple file upload form for my website. I'm using
js.I am trying to create a file upload using node.js and mongodb.I am getting
I'm trying to create an upload file, and email as an attachment form where
I'm trying to create a form where users can save their progress. I have
I am getting the following error when trying to upload an image using paperclip
Little question: I'm trying to create a Form to upload a file. Now i
I'm trying to create a form using Zend_Form (Zend_Framework component). The users should be
I am trying to upload file to rackspace cloud file using the following code:
I am trying to create an upload form that allows the user to select
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can

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.