Q. One
Q. One

Reputation: 1

The controller loads only a String object, but not an html page

The controller loads only a String object, but not an html page. Page login.html is in directory templates. Effect is text 'login" on page. Project is in Spring Boot.

@RestController
public class Company {

    @RequestMapping("login")
    public String company() {
        return "login";
    }
}

@SpringBootApplication
public class ComJonkSpringBootMvcApplication {

    public static void main(String[] args) {
        SpringApplication.run(ComJonkSpringBootMvcApplication.class, args);
    }
}

<!DOCTYPE HTML>
<html>
<head>
    <title>Yahoo!!</title>
</head>
<body>
    Name : <input name="name" type="text" /> Password : <input name="password" type="password" /> <input type="submit" />
</body>
</html>

Upvotes: 0

Views: 79

Answers (1)

Guillaume F.
Guillaume F.

Reputation: 6473

Do not use @RestController if you plan to return a JSP.

Use @Controller instead, and read the documentation about @ResponseBody:

Annotation that indicates a method return value should be bound to the web response body. Supported for annotated handler methods in Servlet environments.

Upvotes: 1

Related Questions