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

  • Home
  • SEARCH
  • 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 6018081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:13:21+00:00 2026-05-23T03:13:21+00:00

I have this use case for which I am generating an image in the

  • 0

I have this use case for which I am generating an image in the getPost method of servlet.
I was saving the image in the local file system at /tmp/xyz.jpg and then doing something like

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<title>Example</title>");
out.println("<body><h2>Graph is :</h2>");
out.println("<img src='/tmp/TimeSeriesChart.jpg'></body>");
out.println("</html>");  

Naturally the image did not get displayed when I hit the URL (to call servlet).

The reason I think was that img src is calculating against the Application’s Root not fileSystem’s Root.

So to summarize I want to be able to save the image at a proper place relative to Application Root , access the image and display it.

Q1. How to find the Application Root within the servlet. So that I can save the image rightly.

Q2. How advisable is to set the content as image and then read it as bytes and display :
http://www.exampledepot.com/egs/javax.servlet/GetImage.html

  • 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-23T03:13:22+00:00Added an answer on May 23, 2026 at 3:13 am

    Ans1: ServletContext.getRealPath() will give you the app root location.

    Ans2: Nothing wrong in having a servlet, but Container doing that would handle the following cases as well:

    1. If-Modified-Since, sends SC_NOT_MODIFIED response
    2. Caching the image data in container for subsequent requests.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this use case of an xml file with input like Input: <abc
I have this use case scenario: there are places which are either playgrounds, restaurants,
I have this .bat script which I use to maven package my application. Problem
I have this method call I have to use... financial_document.assets.length But financial_document.assets could be
I have this textbox I use to capture keyboard shortcuts for a preferences config.
i have this application but how to use its? and example for 7-zip can?
I have this nice little MSBuild-based daily build setup that I use on my
i have this crazy label for each time i create a migration that use
I have this custom textbox that I am working on and I can use
Ok I have this problem I'm trying to use Jquery to load a partial

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.