Suppose there is some code:

PrintWriter out = response.getWriter(); out.write(getPageWithImage(imagePath)); out.close(); 

Inside the getPageWithImage method, we generate html markup, and in the img tag we put our image, whose path we passed to the method.

Question: how do I display? The path that will be specified in the html markup will be local: C:/example/images. How to make the path relevant to the localhost:8080/servlet/img.png ?

    1 answer 1

    You need to specify the path in the form:

     C:\\example\\images\\ + имя картинки (image.png) 

    Or in the project create a folder RESOURCES (resources) to store all the pictures there then you will only need to specify the name of the file with the extension and that's it. It will be better .

    Concerning

     localhost:8080/servlet/img.png 

    So far, nothing to say.