Spring-Security笔记2 自定义登录界面

在实际项目,我们肯定会使用自己的登录界面,spring-security提供的登录界面不实用。

在spring-security.xml中加入以下配置:

<sec:form-login login-page="/toLogin.do"
login-processing-url="/login.do" authentication-failure-url="/toLogin.do?message=authentication-failure"
authentication-success-handler-ref="customLoginSuccessHandler"
username-parameter="username" password-parameter="password" />

其中参数的解释:

login-page:登录页面 

login-processing-url:自定义的登录提交action名称,需要与登录form中的action保持一致 

authentication-failure-url:登录失败后跳转的页面 

default-target-url:登录成功后跳转的页面,如果配置了authentication-success-handler-ref则不生效

username-parameter:登录用户名的参数名称,需要与登录form中的input name='username'保持一致

password-parameter:登录密码的参数名称,需要与登录form中的input name='password'保持一致

authentication-success-handler-ref:自定义登录成功后的Handler


登录界面表单示例:

<form action="login.do" method="post">  
        用户名:<input name='username' type='text'  value='yangyi' ><br />  
        密码:<input name='password' type='password'  value='123456'/>  <br />  
              <input name="submit" type="submit" value="提交" />  
	      <input name="reset" type="reset" value="重置" />  
</form>  

注意表单中input的name属性与spring-security.xml配置中有关属性的对应关系


在spring-security.xml中配置登录界面不拦截:

<sec:http pattern="/toLogin.do" security="none" />



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值