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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:29:51+00:00 2026-05-26T07:29:51+00:00

Using Tomcat and Struts 2. public FileAction class { …… public upload() { …..

  • 0

Using Tomcat and Struts 2.

public FileAction class
{ 
    ......
    public upload()
    {
        .....   
        String fullFileName = request.getContextPath() + "/productImages/" + filename;
        File theFile = new File(fullFileName);
        FileUtils.copyFile(upload, theFile);
        .....
    }
 }

The problem is when I upload an image it will not add image in localhost:8085/shoppingCart/productImages and also not give any exception.

But when i write String fullFileName="c:upload/productImages/" + filename; it will save the file at c:upload/productImages/ path

mean working normal in c:upload/productImages/ case

  • 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-26T07:29:51+00:00Added an answer on May 26, 2026 at 7:29 am

    If you want the file uploaded to the server’s context, you need to use ServletContext.getRealPath(...) to find the base directory of the deployed application. Note that this will not work if you’re deploying a war file. Uploaded files should go to an absolute location on the server itself.

    For downloading an uploaded image you’d write a stream result (since you’re using Struts 2) and use it to load and stream the uploaded file back to the client.

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

Sidebar

Related Questions

Tomcat Version :5.0.28 JDK: 1.5.0.14 The problem: I am using both hibernate and struts
I am using struts2, for that my struts.xml file contains code like : <?xml
I'm using tomcat 6.0 and struts2. When I try to click on a link
I have a Struts2 webapp, in which I compiled using the Tomcat 5.5 libraries.
I use tomcat. I am developing a web application using struts2, and I use
I'm using Tomcat 5.5 as my servlet container. My web application deploys via .jar
i am using tomcat server and i have added a rhino engine to able
I'm using Tomcat 6.0, and I want to know how can I configure Tomcat's
I'm probably going to be using Tomcat and the Apache Axis webapp plugin, but
I am currently building an application using Tomcat, Spring and JAVA. I am using

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.