[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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>
0
inzaghi
Asked:
inzaghi
4 Solutions
 
evnafetsCommented:
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
 
suprapto45Commented:
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
 
KuldeepchaturvediCommented:
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
 
aflat362Commented:
<img src="<%= request.getContextPath() %>/ImageDisplayerServlet">

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now