2

I do an example from Spring in Action 5. I try to display the homepage with an image. When I start localhost:8080 I see the homepage, but don't see image on it.

I enter HTML from the book:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Taco Cloud</title>
</head>

<body>
    <h1>Welcome to...</h1>
    <img th:src="@{/images/TacoCloud.png}"/>
</body>
</html>

And I add an image in my project in Eclipse: project explorer

Add HomeController class:

package tacos;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController {
    @GetMapping("/")
    public String home() {
        return "home";
    }
}

On display, I get next: enter image description here

PowerStat
  • 3,757
  • 8
  • 32
  • 57

2 Answers2

0

I found why it doesn't work.

When I was adding an image in Eclipse, I clicked right button mouse on src/main/resources/static/images then New-File-Link to file in the file system... I don't move an image in my project catalog. I only created to link on my image in the filesystem.

So I added an image. It is not right...

0

I had the same issue, but using Intelij IDEA. To solve this I changed the line:
<img th:src="@{/images/TacoCloud.png}"/> to <img src="../static/images/TacoCloud.png"/> as mentioned here.

.. - refers to the parent folder

Notice: "link to file in the file system" option doesn't support Intelij IDEA.

invzbl3
  • 5,872
  • 9
  • 36
  • 76