简体   繁体   中英

Thymeleaf static images not being found

I've just added a bootstrap template to the app I'm working on and have been the process of making it, and Thymeleaf like each other.

I'm unable to serve up the images when I head off to different pages - I've tried both contextual using the th:src="@{/img/name.png}" notation and the server th:src="@{~/img/name.png}" that I've read through in the docs.

When run the application is accessed via : http://localhost:8080/ , there is no 'app name' so to speak which may be the issue as a few of the examples I read through looked to be expected http://localhost:8080/myApp/myPage.html instead.

On this page: http://localhost:8080/home or any other root level page the images are displayed.

On one of these pages I redirect the user to @RequestMapping("/{userid}/users") which resolves to http://localhost:8080/1/games - it's on this page I encounter the errors.

[Error] Failed to load resource: the server responded with a status of 404 () 

With the images being: http://localhost:8080/1/img/icons/double-arrow.png where '1' is the userId that was passed in to the controller.

My css / img files are in resources/static/css and resources/static/img . I've checked and confirmed that they exist.

I'm using fragments for the header and footer, the css and js files don't have a problem.

Any suggestions on how to resolve would be great, thanks!

edited to add some clarity:

This is part of the html page,

 <a href="games.html" th:href="@{/{userid}/users}"/></a>

the controller:

@RequestMapping("/{userid}/users")
    public String userGames(@PathVariable final Long userid, Model model){

...get, other methods, etc
        return "users";

The '1' that can be seen in the url above is the userid that issuing passed in.

My guess is that your image url is wrong. Shouldn't it be th:src="@{/img/name.png}" since you said you put it in folder resources/static/img ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM