setting the src reference on an image to a servlet

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

Who is Participating?
evnafetsConnect With a Mentor Commented:
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())

suprapto45Connect With a Mentor Commented:
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.

KuldeepchaturvediConnect With a Mentor Commented:
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..
aflat362Connect With a Mentor Commented:
<img src="<%= request.getContextPath() %>/ImageDisplayerServlet">

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.