O
O
Oleg Mikhailov2018-02-17 21:22:44
Java
Oleg Mikhailov, 2018-02-17 21:22:44

How to return html page in Spring Boot?

Good evening
Terribly stupid question, I already wrote using Spring mvc + jsp, but now I can’t understand why the controller doesn’t just return an html document. Here is Spring Boot with Web module.

@Controller
@RequestMapping(value = "/test")
public class Main {

    private static final Logger logger = Logger
            .getLogger(Main.class.getName());

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String index() {
        return "templates/hello.html";
    }

I tried calling return templates/hello.html and just templates/hello
And the html itself is in resources/templates:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>HelloWorld</title>
</head>
<body>
HELLO
</body>
</html>

Returns an error:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Feb 17 20:22:24 EET 2018
There was an unexpected error (type=Not Found, status=404).
no message available

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yerlan Ibraev, 2018-02-19
@mad_nazgul

In spring-boot, you don't need to write a controller for a static page.
All static content (if it's a jar) should be in "resources/static/".
If you want the web components to be in "webapp/", then indicate that you are building war, not jar.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question