setting the src reference on an image to a servlet

Posted on 2006-06-08
Last Modified: 2010-04-01
I have an image tag how do I set the src to point to a servlet.
My servlet name is ImageDisplayerServlet. Do I need to specify absolute or relative patths?

in the web.xml I have the following setting

Question by:inzaghi
    LVL 4

    Accepted Solution

    Absolute or relative makes no matter, as long as the url resolves to something like


    If you use an absolute path, make sure you include the context name (with help from request.getContextPath())

    LVL 16

    Assisted Solution

    May I know why do you want your image src to point to servlet?

    If even the servlet is generating the images, the right way would be -> Servlet Generates Images then Servlet Return the File Name of the Images and then the JSP will show the image by pointing the src dynamically to the images file name.

    LVL 19

    Assisted Solution

    One more thing to take care of is to make sure that your servlet sets the content tyep as image/gif or image/jpeg for image to show properly..
    LVL 3

    Assisted Solution

    <img src="<%= request.getContextPath() %>/ImageDisplayerServlet">


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now