Spring+Spring Security+JSTL实现的表单登陆的例子(二)

2014-11-24 03:24:23 · 作者: · 浏览: 1
8 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 html plain"><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <html> <head> <title>Login Page title> <style> .errorblock { color: #ff0000; background-color: #ffEEEE; border: 3px solid #ff0000; padding: 8px; margin: 16px; } style> head> <body onload='document.f.j_username.focus();'> <h3>Login with Username and Password (Custom Page) h3> <c:if test="${not empty error}"> <div class="errorblock"> Your login attempt was not successful, try again.<br /> Caused : ${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message} div> c:if> <form name='f' action=" value = 'j_spring_security_check' />" method='POST'> < table > < tr > < td >User: td> <td><input type='text' name='j_username' value=''> td> tr> <tr> <td>Password: td> <td><input type='password' name='j_password' /> td> tr> <tr> <td colspan='2'><input name="submit" type="submit" value="submit" /> td> tr> <tr> <td colspan='2'><input name="reset" type="reset" /> td> tr> table> form> body> html>

hello.jsp

1 2 3 4 5 6 7 8 9 10 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <html> <body> <h3>Message : ${message} h3> <h3>Username : ${username} h3> <a href=" /j_spring_security_logout" />" > Logout a > body> html>

6.例子

1.当访问“http://localhost:8080/SpringMVC/welcome”链接时,Spring Secutiry将会跳转到登陆页面:
http://localhost:8080/SpringMVC/login

\

2.如果用户名和密码输入错误则认证失败,页面将会展示错误信息:

\

3.如果用户名和密码输入正确则认证成功,则会展示请求页面:

http://localhost:8080/SpringMVC/welcome

本文为原创文章,转载请注明出处,首发于http://www.it161.com/article/javaDetail articleid=140107232125

更多IT文章,请访问http://www.it161.com/