spring security起步二:自定义登录页

在上一篇文章 spring security 起步:框架搭建 最后,我们可以看到spring security自动为我们生成了一个默认的登录页。首先呢 那个登录页太丑,其次呢登录时我们也想实现一些其他的功能:比如找回密码,Remember me等。那么 我们如何实现自定义登录页功能呢?

添加登录页 login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>




Insert title here



	

请输入您的用户名与密码

用户:
密码:


实现登录的Controller

@Controller
public class LoginController {

	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String loginPage() {
		return "login";
	}
}

配置spring security

在上面的配置中,通过指定url /login 跳转到login.jsp页面。那么接下来就是告诉spring security 我想使用自己定义的登录页,而且还要告诉spring security不能拦截我的登录页面。具体配置如下:




	

	
		
		
	
	
		
			
				
			
		
	

启动项目 可以看到我们自定义的登录页面

spring security起步二:自定义登录页_第1张图片

源码下载

https://github.com/SmallBadFish/spring_security_demo/archive/0.1.0-customlogin.zip

你可能感兴趣的:(spring,security)