Authenticating users using a custom login page
In this recipe, you'll learn how to build your own login form instead of using Spring's default login form.
How to do it…
Here are the steps to define a custom login page:
Make sure that the JSTL Maven dependency is declared in
pom.xml
:<dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
Make sure that a JSP view resolver is declared in the
AppConfig
class:@Bean public ViewResolver jspViewResolver(){ InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setViewClass(JstlView.class); resolver.setPrefix("/WEB-INF/jsp/"); resolver.setSuffix(".jsp"); return resolver; }
Add a controller method for the login page in a controller class:
@Controller public class UserController { @RequestMapping("login") public String login() { return "login"; } …
Add a JSP for...