@Controller
public class ExampleController {

  @GetMapping(value = {"/", "/index.html"})
  public String homePage(Model model) {
    model.addAttribute("msg", "Hello World!");
    return "views/home/index";
  }

  @GetMapping(value = "/page1.html")
  public String page1(Model model) {
    // ...
    return "views/home/page1";
  }

  @GetMapping(value = "/page2.html")
  public String page2(Model model) {
    // ...
    return "redirect:/index.html";
  }

  @GetMapping(value = "/page3.html")
  public String page3(Model model) {
    // ...
    return "forward:/page1.html";
  }

}


Response Headers and Payload

  • Request / or /index.html
curl -v http://localhost:8080/
...
< HTTP/1.1 200
...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en"
  xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>Spring Boot 3.x + Thymeleaf + Themes + AWS + Home page</title>
...
More HTML content


  • Request /page2.html
curl -v http://localhost:8080/page2.html
...
< HTTP/1.1 302
< Location: http://localhost:8080/index.html
...
No HTML content

The HTTP 302 status code indicates the resource has been temporally moved to the URL included in the Location Header.
The browser reads the Location Header and follows with another request to that URL.


  • Request /page3.html
curl -v http://localhost:8080/page3.html
...
< HTTP/1.1 200
...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en"
  xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>Spring Boot 3.x + Thymeleaf + Themes + AWS + Page 1</title>
...
More HTML content