0

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>
1
  • 1
    A couple of side notes: It's customary to name controller classes something ending in ...Controller, and if you're already using Spring Boot, you may as well use Spring Security, which still wants the HTML for the login page but will take care of the mapping itself. Commented Mar 26, 2017 at 2:12

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Technically, an HTML page is a REST response, but the Spring annotation does have that restricted meaning.
I have now statement 'Circular view path [login]: would dispatch back to the current handler URL [/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.'
You should read Spring Security getting started : docs.spring.io/spring-security/site/docs/current/guides/html5//… / In general with Spring or any library, read the documentation before using it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.