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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:50:25+00:00 2026-06-16T05:50:25+00:00

I am running Eclipse Java EE and tomcat for running my webapp. I used

  • 0

I am running Eclipse Java EE and tomcat for running my webapp. I used the following code to store an image file to the upload/images/profilepics directory:

public String uploadPhoto() {
    try {
        //get path to upload photo
        String filePath = servletRequest.getSession().
                getServletContext().getRealPath("/uploads/profilepics");

        System.out.println("Server path:" + filePath);

        //creating unique picture name
        Map sess = (Map) ActionContext.getContext().get("session");
        Integer uid = (Integer) sess.get("uid");
        String profilePictureName = uid + "-" + 
                MyUtilityFunctions.createVerificationUrl() + this.userImageFileName;

        //update user record
        //tobe done 
        String imgUrl = filePath + profilePictureName;
        ViewProfileModel pofilePictureUpdate = new ViewProfileModel();
        pofilePictureUpdate.updateUserPhotoUrl(imgUrl, uid);

        //create new File with new path and name
        File fileToCreate = new File(filePath, profilePictureName);

        //copy file to given location and with given name
        FileUtils.copyFile(this.userImage, fileToCreate);
    } catch (Exception e) {
        e.printStackTrace();
        addActionError(e.getMessage());

        return INPUT;
    }
    return SUCCESS;
}

after printing filePath I got the following result:

Server Path: /home/bril/webspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/picvik/uploads/profilepics

Now the problem is, I am not able to get the image or if I give the same url to <img src=""> nothing is getting displayed.

Please correct where I am doing wrong.

  • 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-16T05:50:26+00:00Added an answer on June 16, 2026 at 5:50 am

    There are suggestions:

    1. there are lots of reason, that you shouldn’t save user images in this way, just like @DaveNewton mentioned in another question. There
      are some post to help you make your decision:

      • Post1
      • Post2

      My personal opinion is to save them into DB, because you don’t want
      to let your user lost their images.

    2. If you need access session, you can check out SessionAware. This should be a better way to access session.
    3. You are using tomcat as application container, you can configure the server to use its local installation, which makes you easier to track the problem in this case. check out this picture belowTomcat Server location

    Back to your question, There are different ways to do this:

    • if you cannot find the image user just uploaded, you can check it
      manual, see 3.
    • Otherwise, you could try <img src="/uploads/profilepics/<s:property
      value='profilePictureName'/>"
    • Or you can get this picture using stream, here is the snippet:

    JSP:

        <img src="
            <s:url var="profilePic" action="customer-image-action">
                <s:param name="uid" value="%{uid}"/>
            </s:url>
        " alt="kunden logo" />
    

    Action:

    public String execute() throws Exception {
        // filename = somehow(uid);
        HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
        imgPath = request.getSession().getServletContext().getRealPath("/uploads/profilepics/")+filename;
        log.debug("context-path: " + imgPath);
        try {
            inputStream = FileUtils.openInputStream(new File(imgPath));
        } catch (IOException e) {
            log.error(e.getCause(), e);
        }
        return SUCCESS;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i get this exception frequently when running my app on tomcat using eclipse: java.lang.OutOfMemoryError:
I've got a Java webapp running on one tomcat instance. During peak times the
I am running Eclipse Pulsar with Java ME SDK 3.0. When I try running
So I'm running Mac OSX Lion and I recently installed Eclipse IDE for Java
I have the following: running eclipse-indigo in CentOS 6.2 , I also installed apache-ant-1.8.4
When running buildr eclipse builder generates (among others) following entry in .classpath : <classpathentry
I'm running Eclipse Helios Service Release 1, with Tomcat 7.0.12 in Linux Ubuntu Natty
I am running Eclipse Galileo with Tomcat 6.0.18. Currently, I have a working application
What's the easiest way for me to get Eclipse running with a Java servlet
I use eclipse for java EE as my IDE and tomcat as my server.

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.