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

  <servlet-mapping>
    <servlet-name>ImageDisplayerServlet</servlet-name>
    <url-pattern>/reports/ImageDisplayerServlet/*</url-pattern>
  </servlet-mapping>
inzaghiAsked:
Who is Participating?
 
evnafetsConnect With a Mentor Commented:
Absolute or relative makes no matter, as long as the url resolves to something like

http://[host]/[webapp]/reports/ImageDisplayerServlet/myImage
eg
http://localhost:8080/myWebApp/reports/ImageDisplayerServlet/myImage

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

0
 
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.

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

0
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.