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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:17:53+00:00 2026-05-26T18:17:53+00:00

I am new to java, and am trying to add an image ‘space.gif’ from

  • 0

I am new to java, and am trying to add an image ‘space.gif’ from a file path through a html servlet.

public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
{              
  response.setContentType("text/html");

  PrintWriter out = response.getWriter();

  out.print("<HTML>");
  out.print("<HEAD><TITLE>Upload Image</TITLE></HEAD>");
  out.print("<BODY>");

  out.print("<img src='space.gif' alt='image' />");

  out.print("</BODY>");
  out.print("</HTML>");
  out.close();
}
  • 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-26T18:17:54+00:00Added an answer on May 26, 2026 at 6:17 pm

    If you put the space.gif at the right location in the public web content and reference it by the right URL, then it’ll work fine. As you have it right now, its location is dependent on the URL with which the servlet is been invoked. Basically, it should be virtually in the same folder as the servlet.

    This example should do:

    WebContent
     |-- images
     |    `-- space.gif
     `-- WEB-INF
          |-- classes
          `-- lib
    

    with

    out.print("<img src='" + request.getContextPath() + "/images/space.gif' alt='image' />");
    

    Or, if that image is actually located outside the public web content and you can’t move it in the public web content for some unobvious reason, then you’d need to add an extra web application context to your server configuration pointing to that folder, e.g. /images, so that you can do

    out.print("<img src='/images/space.gif' alt='image' />");
    

    See also:

    • Load images from outside of webapps / webcontext / deploy folder using <h:graphicImage> or <img> tag

    Unrelated to the concrete problem, HTML belongs in JSP, not in Servlet.

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

Sidebar

Related Questions

I'm trying to write some code to look through an image file for groups
I'm trying to make a Frame from which I want to add an image
I am new to Java and am trying to run a program using Eclipse.
Just a warning: I'm completely new to Java and am trying to teach myself
I'm new to java and I'm trying to swap out the text on a
Hey I'm new to java servlets and I am trying to write one that
I'm pretty new to Java ME and i'm trying to use Microlog to handle
I know something about Java but completely new to Enterprise Java. I'm trying my
I'm trying to deploy a java application to appspot (google appengine). I'm new to
I am very new to processing.org and Java. I am trying to store objects

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.