Spring Security学习笔记自定义登录页面(二)
2017-07-26 16:46
633 查看
在入门(一)是有问题的:
在做项目的时候,登录页面都是需要自己写的,并且登录页面是不需要验证直接可以访问的。
用户名和密码直接写在配置文件中,而实际项目中我们是放在数据库中的。
在之前 Spring Security 框架生成的登录页面中直接输入用户名和密码提交后,Spring Security框架替我们进行验证的
由于验证过程是 Spring Security 框架自动完成的,所以在我们的登录页面中表单元素的 name都是固定的
现在自己新建一个登录页面login.jsp
写完登录页面后,需要指定spring Security跳转到我们写的登录页面
springSecurity.xml配置
访问我们的项目,发现已经可以跳转到我们自己写的登录页面了
在做项目的时候,登录页面都是需要自己写的,并且登录页面是不需要验证直接可以访问的。
用户名和密码直接写在配置文件中,而实际项目中我们是放在数据库中的。
在之前 Spring Security 框架生成的登录页面中直接输入用户名和密码提交后,Spring Security框架替我们进行验证的
由于验证过程是 Spring Security 框架自动完成的,所以在我们的登录页面中表单元素的 name都是固定的
现在自己新建一个登录页面login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>登录页面</title> </head> <body> <form name='f' action='/springSecurity/j_spring_security_check' method='POST'> <table> <tr> <td>用户名:</td> <td><input type='text' name='j_username' value='user'></td> </tr> <tr> <td>密码:</td> <td><input type='password' name='j_password' /></td> </tr> <tr> <td ><input name="submit" type="submit" value="登录"/></td> <td ><input name="reset" type="reset" value="重置"/></td> </tr aae4 > </table> </form> </body> </html>
写完登录页面后,需要指定spring Security跳转到我们写的登录页面
springSecurity.xml配置
<?xml version="1.0" encoding="UTF-8"?> <b:beans xmlns="http://www.springframework.org/schema/security" xmlns:b="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> <!-- 这表示,我们要保护应用程序中的所有 URL,只有拥有 ROLE_USER 角色的用户才能访问 --> <http auto-config="true"> <intercept-url pattern="/*" access="ROLE_USER"/> <!-- login-page指定登录页面 /login.jsp* 加个*号是防止请求时后面带了参数 filters="none" 表示不拦截 --> <form-login login-page="/login.jsp"/> <intercept-url pattern="/login.jsp*" filters="none"/> </http> <!-- 配置认证管理器 --> <authentication-manager> <authentication-provider> <user-service> <user name="user" password="user" authorities="ROLE_USER"/> </user-service> </authentication-provider> </authentication-manager> </b:beans>
访问我们的项目,发现已经可以跳转到我们自己写的登录页面了
相关文章推荐
- Spring Security 学习笔记-登录认证过滤器
- Spring Security教程(3)---- 自定义登录页面
- Ferris教程学习笔记:js示例5.7 自定义右键菜单,请在页面点击右键查看效果。
- Spring Security教程(3)---- 自定义登录页面
- spring security自定义登录页面
- 【WPF学习笔记】之如何传递第一个登录界面的值到下一个页面显示:动画系列之(三)
- React-Native学习笔记之:实现简单地登录页面
- 学习笔记之php页面ajax登录异步刷新
- spring security之自定义登录页面
- 网上图书商城项目学习笔记-002登录页面的静态设计
- C#网站登录学习笔记(二):访问需登录后才能访问的页面
- Spring Security学习笔记-自定义Spring Security过滤链
- 【学习笔记⑦】登录页面怎样实现验证码登录功能
- Spring Security教程(3)---- 自定义登录页面
- C#网站登录学习笔记(二):访问需登录后才能访问的页面
- 学习博客园开源代码笔记(登录页面)
- Django 开发学习笔记(3)- 编写自定义的页面
- 转:Spring学习笔记---Spring Security登录页
- JSP基础实例_登录页面的制作_学习笔记
- Spring Security 自定义登录页面