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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:05:40+00:00 2026-06-04T18:05:40+00:00

I want to implement an upload component in my servlet file,but it doesn’t work.

  • 0

I want to implement an upload component in my servlet file,but it doesn’t work.
The code episode seems like follows:

SmartUpload smartUpload=new SmartUpload();
StringBuffer stringBuffer=new StringBuffer();
smartUpload.initialize(config,request, response);
try {
     smartUpload.upload();
 File file=smartUpload.getFiles().getFile(0);
 stringBuffer.append(file.getFileName());
 file.saveAs("/upload_resources/"+stringBuffer);
} catch (SmartUploadException e) {
 e.printStackTrace();
}

The upload_resource directory is just under the WebRoot directory,the code runs without any errors ,but the file is just not uploaded. By the way , even I changed the line

file.saveAs("/upload_resources/"+stringBuffer);

to

file.saveAs(request.getRealPath("/upload_resources/")+"/"+stringBuffer);

that is to use an absolute path, the file is not uploaded.
Any help will be appreciate. Thanks.

  • 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-04T18:05:42+00:00Added an answer on June 4, 2026 at 6:05 pm

    I’ve never really worked with SmartUpload, but I can tell that you shouldn’t be saving uploaded files in the webapp’s deploy folder. They may all get lost whenever the webapp get redeployed with the simple reason that the uploaded files are not contained in the original WAR file. So you should not prepare the upload folder in the webapp’s deploy folder, but on a fixed path outside the deploy folder.

    If SmartUpload is well designed, I’d expect that

    file.saveAs("/upload_resources/"+stringBuffer);
    

    will save it to the /uploaded_resources folder on the root of the same disk as where the webserver is started from. So in for example Windows that would be C:\uploaded_resources. Prepare and use that folder instead.

    Further there’s another potential problem when you’re using the MSIE browser. This browser namely incorrectly includes the full client side path in the filename. I’m not sure if SmartUpload handles this properly, but you might want to debug the actual value of file.getFileName() and make sure that it’s really only the filename in the form of filename.ext. Otherwise, you’d need to use String#substring() to substring the part after the last / and \.

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

Sidebar

Related Questions

I want to implement file upload in RESTful way using openrasta but not able
i want to implement the simple file upload without flash.. and single file, but
I want to implement a minor file system like collection in MongoDB . So
I want to implement a multi file upload I was thinking if its possible
I want to implement file upload progress monitor bar over file upload functionality of
I want to implement an asynchronous file upload for my asp.net application. My idea
At moment I want to implement picture upload without using any plug-ins. My upload
I just implemented an image upload to MySQL via PHP. But i want to
I want implement in my software solution an VBA editor but in c# 3.0.
I want to implement email application which has all options like inbox,compose,drafts and etc.

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.