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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:14:02+00:00 2026-05-13T09:14:02+00:00

I want to display the image located in my local drive. I am using

  • 0

I want to display the image located in my local drive. I am using sun java app server 8. For example If I generate a file abc.jpg dynamically and store it in c:\abc.jpg, then how could I use it in jsp or servlets? How to display it in the jsp or servlet pages?
I know giving the path c:\abc.jpg in coding to display image wont work , because it is out of webserver..

  • 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-13T09:14:03+00:00Added an answer on May 13, 2026 at 9:14 am

    Basically just create a Servlet which gets an InputStream of it with help of FileInputStream and writes it to the OutputStream of the HttpServletResponse along with a correct set of response headers with at least the content-type. Finally call this servlet in the src attribute of the <img> element along with the file identifier as request parameter or pathinfo. E.g.:

    File file = new File("c:/abc.jpg");
    
    response.setContentType(getServletContext().getMimeType(file.getName()));
    response.setHeader("Content-Length", String.valueOf(file.length()));
    response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
    
    BufferedInputStream input = null;
    BufferedOutputStream output = null;
    
    try {
        input = new BufferedInputStream(new FileInputStream(file));
        output = new BufferedOutputStream(response.getOutputStream());
    
        byte[] buffer = new byte[10240];
        int length;
        while ((length = input.read(buffer)) > 0) {
            output.write(buffer, 0, length);
        }
    } finally {
        if (output != null) try { output.close(); } catch (IOException logOrIgnore) {}
        if (input != null) try { input.close(); } catch (IOException logOrIgnore) {}
    }
    

    You can find here a complete basic example: http://balusc.blogspot.com/2007/04/imageservlet.html

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

Sidebar

Related Questions

I want to display an image using this php script on my server. $file
I want to display an image located in the app-storage directory of my AIR
I want to display image using base64 encoding in IE using GWT If it
I am using the fancybox.I want to display the image gallery using the galleria
i want to display image in UIImageView which is on the UIScrollView and using
I am using asp.net with C# [3.5]. I want to display Image before my
I want to display image on UIImageView using URL and NSString . I am
I want to display .jpg image in an Qt UI. I checked it online
I want to display an image at the bottom of the screen and make
I want to display an image in my MKMapView instead of little rock pin

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.