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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:53:03+00:00 2026-05-25T05:53:03+00:00

I am working on an application where the information of users gets added and

  • 0

I am working on an application where the information of users gets added and modified(updated).

In add module, admin enters user details and unique-id(abc001) gets generated at “add” button. and admin also saves the image/picture(name : abc001) of the user in server location (//some-location-ip address/D drive/images).

In “update” module, admin can modify the user details, but can not modify id.

I need some direction in couple of scenarios.

If an Admin “updates” a particular user, the image of that user which is present in the server should gets displayed on the page as soon as the admin hit the update button.

Image code in JSP :

<img height="100px;" width="100px;" src="........." alt="Candidate Image"></img>

I have written a servlet, but don’t know how to call different images corresponding to different users and display the image on the profile page.

user A profile will display user A image
user B profile will display user B image
and so on

Servlet code Snippet

public class UpDatePhoto extends HttpServlet {

    public UpDatePhoto () {
        super();
        // TODO Auto-generated constructor stub
    }

   private static final long serialVersionUID = -8071854868821235857L;
   private static final int DEFAULT_BUFFER_SIZE = 10240; // 10KB.
   private String imagePath;

   *public void init() throws ServletException {
        this.imagePath = "D:\\photo_not_available_large.png";
    }*

   protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
        String requestedImage = request.getPathInfo();
        if (requestedImage == null) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
            return;
        }

        File image = new File(imagePath, URLDecoder.decode(requestedImage, "UTF-8"));

        String contentType = getServletContext().getMimeType(image.getName());

        if (contentType == null || !contentType.startsWith("image")) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
            return;
        }

        response.reset();
        response.setBufferSize(DEFAULT_BUFFER_SIZE);
        response.setContentType(contentType);
        response.setHeader("Content-Length", String.valueOf(image.length()));
        response.setHeader("Content-Disposition", "inline; filename=\"" + image.getName() + "\"");

        BufferedInputStream input = null;
        BufferedOutputStream output = null;

        try {

            input = new BufferedInputStream(new FileInputStream(image), DEFAULT_BUFFER_SIZE);
            output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);

            byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
            int length;
            while ((length = input.read(buffer)) > 0) {
                output.write(buffer, 0, length);
            }
        } finally {

            close(output);
            close(input);
        }
    }


    private static void close(Closeable resource) {
        if (resource != null) {
            try {
                resource.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

} 

The image is not http accessible but is only accessible as a file, the servlet would have to open the image file, read in the contents and place those in the response buffer” ….not sure if i am correct.

Can somebody guide me to the direction and help me out as how to fetch the image from the server directory location and display the correct image for a user.

  • 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-25T05:53:03+00:00Added an answer on May 25, 2026 at 5:53 am

    I have a hard time in understanding the concrete problem, but I believe that your root problem is that you don’t know how to set the imagePath accordingly? It has namely a wrong value.The code shows that it should be set to the root folder where all images are been placed. In the underlying operating system platform, you need to map //some-location-ip address/D drive/images as a network drive in Windows explorer, e.g. Z: and then use that in your imagePath instead.

    this.imagePath = "Z:";
    

    It also expects the image file name as request pathinfo. So, assuming that your servlet is mapped on an URL pattern of /images/*, then your <img src> should look basically like this

    <img src="images/filename.png" />
    

    You could also fill it dynamically with EL. E.g. with the unique username of the logged-in user:

    <img src="images/${user.name}.png" />
    

    As to using the "D:\\photo_not_available_large.png" replacement image, you could set that when File#exists() returns false.

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

Sidebar

Related Questions

I am working on an application where users enter information that is then added
I am working on an application which has got some sensitive information. I am
I'm working on an application. I have a servlet (writeDataBase.class) that writes some information
REASON: I'm working on an emergency alert application that needs to display information on
I've got (working) application done with ttk. It uses self-created module for showing a
I am working an application having I18N support. In this application, based on user's
I'm currently working on an application that users a number of different views to
I'm working on a application where users can be placed in a group. The
I'm working on the admin application for another application. Within the application are several
I'm working on a simple AJAX chat add-on for my PHP application so I

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.