0

I am doing a Spring Boot project where I have a folder in src/main/resources called static and another folder called images inside. I´m using thymeleaf and HTML to display an image, but never shows it. I use Spring Security, that could be the problem. I tried with a lot of different paths and routes to verify if it was misspelled but that was not the case.

I use this code in the html:

<img th:src="@{img/planet.jpg}" class="img-thumbnail" style="max-width: 200px" />

And the folder structure is:

image of the folder structure

The HTML file that displays the image is "cambioPassword.html" and the image is "planet.jpg" I also can provide a link to my repository in case anyone wants to take a deep look, I would be very thankful.

I was trying to use different paths and still nothing, instead of the image I only see the default icon.

SternK
  • 11,649
  • 22
  • 32
  • 46
Redox
  • 11
  • 2
  • Hello, try this: th:src="@{/img/planet.jpg}" – Mar-Z Apr 18 '23 at 09:34
  • @Mar-Z doesn´t work – Redox Apr 18 '23 at 10:25
  • Hi. Try to check in browser to which path the image source link is rendered. Then check, if the picture is available under that path. If not, try figuring out under which path the image would be available (maybe it was not copied to the server). Then you can adjust either the path in html or the image location. – Bertolt Apr 18 '23 at 11:27
  • @Bertolt the path is correctly rendered, also I copy and paste the path into the browser url and the image loads, but in the web app doesn't – Redox Apr 18 '23 at 15:20
  • @Redox If the path is rendered correctly in the HTML, then probably some browser restrictions prohibit the image from being displayed, like e.g. in this example https://stackoverflow.com/questions/18413929/html-image-not-displaying-while-the-src-url-works Could you provide more details about the rendered HTML code and where the image is located for the browser to access? – Bertolt Apr 19 '23 at 08:05

0 Answers0