Image Src for calling a Servlet

后端 未结 3 1768
既然无缘
既然无缘 2021-01-29 06:15

I want to call a Servlet from img src. I have defined a Servlet class with name ImageProducerServlet and registered it in web.xml:


   

        
3条回答
  •  盖世英雄少女心
    2021-01-29 06:41

    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.

    See also:

    • How get the base URL?

提交回复
热议问题