spring-security3笔记二
自定义登录界面
spring-security会自动生成登录表单,但是一般情况下程序都需要自己定义登录界面。
一、新建登录页面文件
添加登录表单,以及相关字段,表单的响应请求为:j_spring_security_check
用户名和密码的字段名如下:
<form action="${pageContext.request.contextPath}/j_spring_security_check" method="post">
<table width="300px">
<tr>
<td width="30%">姓名:</td>
<td width="70%"><input type="text" name="j_username" /></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="j_password" /></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
2、security配置文件
使登录界面不受security的拦截:
<sec:http pattern="/login.jsp*" security="none">
</sec:http>
使所有需要登录的页面跳转到登录页面:
<sec:http auto-config="true" access-denied-page="/html/access_denied.jsp">
<sec:form-login login-page="/login.jsp"
default-target-url="/index.jsp" />
<sec:intercept-url pattern="/admin.jsp*" access="ROLE_ADMIN" />
<sec:intercept-url pattern="/**" access="ROLE_USER" />
</sec:http>
现在程序就可以使用自定义的登录页面了。