I want to call a Servlet from img src. I have defined a Servlet class with name ImageProducerServlet and registered it in web.xml:
You need to prepend the context path. You preferably won't hardcode it as the context path is a server-controlled setting. You can obtain it from the HTTP request as follows:
<img src="#{request.contextPath}/imageProducerServlet" id="id"/>
An alternative is to use the HTML <base>
tag and set it to the URL of the context root. This way every URL which doesn't start with /
will be relative to it.
Just say
<img src="imageProducerServlet" id="id"/>
or
<img src="/mycompany/imageProducerServlet" id="id"/>
If this is working:
http://localhost:7101/mycompany/imageproducerservlet
then you need your img tag to look like that:
<img src="/mycompany/imageProducerServlet" id="id"/>