Skip to content

Serving HTML pages in a Spring Boot application

I have a Spring Boot Application. I am trying to pass a variable to a HTML page but unfortunately I cannot seem to do it, on application start nothing is rendered except the static text: “WORLD”. My controller is as below:

public class IndexController {
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(Model model) {
        model.addAttribute("message", "HELLO");
        return "index";

And my index.html:


I was looking for an answer and I found these articles:

How to serve .html files with Spring

How to serve html files with Spring

How to handle static content in Spring MVC?

These are useful examples, but in my project I don’t have files such as: mvc-dispatcher-servlet.xml, web.xml, or even the whole WEB-INF directory.

The files I have after creating a Spring MVC Project are in the screenshot below. Should I add the files mentioned in the above literature to fix this issue or what?

My Project view via IntelliJ IDEA:

Project Structure

My pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""



        <!-- Java version -->
        <!-- Use UTF-8 sources encoding -->

        <!-- Local model -->

        <!-- Spring boot -->


        <!-- MAIN CODE SETTINGS -->

        <!-- TEST CODE SETTINGS -->






You’re using Thymeleaf as your templating language, and you should read the documentation for it. In Thymeleaf, to substitute a variable, you’ll use an attribute on the HTML tag, so something like this:

<h1 data-th-text="${message}">this gets replaced</h1>
4 People found this is helpful