更新时间:2023-07-28 03:40:11
你们好,最近小艾特发现有诸多的小伙伴们对于spring security 原理,spring security这个问题都颇为感兴趣的,今天小活为大家梳理了下,一起往下看看吧。
1、 第一步是编写web.xml:
2、 ?xml version='1.0' encoding='UTF-8'? web-app xmlns='http://java.sun.com/xml/ns/javaee' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd' version='3.0' display-nameSpringSecurityPrj/display-name context-param param-namecontextConfigLocation/param-name param-value/WEB-INF/springmvc-*.xml/param-value /context-param filter filter-namespringSecurityFilterChain/filter-name filter-classorg.springframework.web.filter.DelegatingFilterProxy/filter-class /filter filter-mapping filter-namespringSecurityFilterChain/filter-name url-pattern/*/url-pattern /filter-mapping listener listener-classorg.springframework.web.context.ContextLoaderListener/listener-class /listener welcome-file-list welcome-fileindex.jsp/welcome-file /welcome-file-list/web-app
3、 步骤2:编写安全性配置文件:
4、 ?可扩展标记语言版本='1.0 '编码='UTF八号'豆子:豆子xmlns=' http://www。spring框架。' xmlns:beans=' http://www。spring框架。org/schema/beans ' xmlns:xsi=' http://www。w3。org/2001/XML架构实例' xsi:schema location=' http://www。spring框架。org/schema/beans http://www。spring框架。org/schema/beans/schema/spring-beans-3.1-自动配置模式,
5、 第三步是编写一个成功登录的jsp页面:
6、 % @ page language=' Java ' content type=' text/html;charset=UTF-8 '页面编码=' UTF-8 ' %!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN ' ' http://www。w3。org/TR/HTML 4/loose。DTD ' htmlheadmeta http-equiv=' Content-Type ' Content=' text/HTML;charset=UTF-8 '标题登录首页/title/head dyspan color=' red '登录成功!/span br/a href=' admin。JSP '管理员。JSP/a/body/html
7、 第四步是编写管理员界面:
8、 % @页语言=' Java '导入=' Java。util。*“页面编码=”UTF-8“% %字符串路径=请求。getcontextpath();string basePath=request。get scheme()'//'请求。获取servername()“:”请求。获取服务器端口()路径“/”;%!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN ' HTML head base href=' %=basePath % ' title管理员页面/title meta http-equiv=' pragma ' content=' no-cache ' meta http-equiv=' cache-control ' content=' no-cache ' meta http-equiv=' expires ' content=' 0 ' meta http-equiv=' keywords ' content=' keyword 1,keyword2,keyword 3 ' meta http-equiv=' description ' content='这是我的页面!-link rel=' style sheet ' type=' text/CSS ' href=' styles。CSS '-/head body p style=' color:red '管理员页面/p /body/html
9、 步骤5:编写自定义登录页面:
10、 % @页语言=' Java '导入=' Java。util。*”页面编码=“UTF-8”% % @ taglib前缀=' c ' uri=' http://Java。星期日com/JSP/jstl/core " % % String path=request。getcontextpath();string basePath=request。get scheme()'//'请求。获取servername()“:”请求。获取服务器端口()路径“/”;%!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN ' HTML head base href=' %=basePath % ' title用户登录/title meta http-equiv=' pragma ' content=' no-cache ' meta http-equiv=' cache-control ' content=' no-cache ' meta http-equiv=' expires ' content=' 0 ' meta http-equiv=' keywords ' content=' keyword 1,keyword2,keyword 3 ' meta http-equiv=' description ' content='这是我的页面!-link rel=' style sheet ' type=' text/CSS ' href=' styles。CSS '-/head body onLoad=' document。f . j _用户名。焦点();c:if test=' $ { not empty param。log in _ error } ' font color=' red '登录失败,
以上就是spring security这篇文章的一些介绍,希望对大家有所帮助。