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:
An alternative is to use the HTML
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.