Image not showing

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Image not showing

wangkh
I am using Thymeleaf with Spring 5 and my HTML has the line below but the image is not showing. What is the value that should be in "th:src"?

<img th:src="images/logo.png" alt="">
The exception is

"2018-09-12 16:59:18.469 ERROR 13736 --- [nio-8080-exec-2] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-8080-exec-2] Exception processing template "index": Could not parse as expression: "images/logo.png" (template: "index" - line 12, col 41)

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "images/logo.png" (template: "index" - line 12, col 41)
        at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:131) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
        at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:62) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
"
Reply | Threaded
Open this post in threaded view
|

Re: Image not showing

Reiju
th:src="@{/images/logo.png}"
Reply | Threaded
Open this post in threaded view
|

Re: Image not showing

wangkh
Still not working. Below is my directory structure. I am referencing the image from index.html and image file is under /images folder.



I am using the Thymeleaf Security example to experiment.
Reply | Threaded
Open this post in threaded view
|

Re: Image not showing

Reiju
This post was updated on .
If u move 'images' folder to WEB-INF, u should change resource location in Config class

registry.addResourceHandler("/images/**").addResourceLocations("/WEB-INF/images/");

PS: in original example all 'static' folders in 'webapp'. Not in 'WEB-INF'
Reply | Threaded
Open this post in threaded view
|

Re: Image not showing

wangkh
Thanks a lot. It is working now.