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

  • Home
  • SEARCH
  • 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 7512909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:00:52+00:00 2026-05-30T00:00:52+00:00

I am using Apache Commons File Uploader API. It is working successfully when I

  • 0

I am using Apache Commons File Uploader API. It is working successfully when I use absolute path like this c:\\my uploads\\. That is file will be uploaded to that place.

I am using NetBeans 7 for development. In my Project Tree, I have created another folder called uploads. So when I use relative paths like uploads/ or /uploads/pics/, it is not working. That is, there is no error. But file is not written to that folder. I am using a object of “File” and using its “write()” function.

My project folder structure is like:

-- C:\
-- -- my project\
-- -- -- school\
-- -- -- -- web\
-- -- -- -- -- index.jsp
-- -- -- -- -- fileupload.jsp
-- -- -- -- -- uploads\
-- -- -- -- -- -- pics\
  • 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-30T00:00:55+00:00Added an answer on May 30, 2026 at 12:00 am

    You basically need to convert the relative web path to absolute disk file system path by ServletContext#getRealPath().

    String relativeWebPath = "/uploads";
    String absoluteDiskPath = getServletContext().getRealPath(relativeWebPath);
    String filename = FilenameUtils.getName(item.getName());
    File file = new File(absoluteDiskPath, filename);
    // ...
    

    However, this approach of writing uploaded files to expanded WAR folder is absolutely not recommended. When you redeploy the WAR, all those uploaded files will get lost (simply because they are not contained in the original WAR!). It will also not work when the server is configured to expand WAR in memory instead of on disk. The getRealPath() would then return null.

    Write uploaded files to a path outside the expanded WAR folder. You did it right at first place. You can always make the upload folder configureable by specifying it as a VM argument or a properties file setting.

    Last but not least, Java code belongs in Java classes, not JSP files.

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

Sidebar

Related Questions

I've written a Servlet that handles file uploads using the Apache commons file upload
I have a simple form that uploads a selected file using Apache Commons Upload
I tried to use the file upload using Apache Commons but the following exception
I am using Apache Commons IO FileUtils utility to read a file into a
I am processing an xml file using apache.commons.digester The xml is, for instance, structured
I'm using Apache Commons e-mail validator and it refuses to accept email address like:
is possible to upload a file on apache server using commons-fileuploader jar file in
I'm using the apache commons fileupload stream api. But the FileItemIterator FileItemIterator iter =
I'm using Apache Commons VFS (Virtual File System) to access some files over SFTP.
I have implemented fileupload functionality using apache commons file upload library and implemented logic

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.