正常的登录
进入自己系统的登录页面,输入用户名密码,登录系统。
单点登录
来到一个第三方的登录页面,输入用户名密码,在这个页面登录成功之后,就算成功的登录了应用系统。好处在于这个登录页面不仅仅是登录一个系统,可以同时登录多个系统。即所谓的一次登录,全程畅通。
另外开一个浏览器
原来的页面刷新一下
发现他已经被挤下线
package com.nx.j2ee.rvice;import org.springframework.stereotype.rvice;import javax.rvlet.http.httpssion;import java.util.hashmap;import java.util.map;@rvicepublic class onlinervice { private map<string, httpssion> urmap = new hashmap<>(); public httpssion geturmap(string name) { return urmap.get(name); } public void turmap(string name, httpssion httpssion) { urmap.put(name, httpssion); } public void delecturmap(string name){ urmap.re幻游记move(name); } public int shownum(){ return urmap.size(); } public map<string, httpssion> showall(){ return urmap; }}
登入controller
package com.nx.j2ee.controller;import com.nx.j2ee.entity.urentity;import com.nx.j2ee.rvice.onlinervice;import com.nx.j2ee.rvice.urrvice;import org.springframework.beans.factory.annotation.autowired;import org.springframework.stereotype.controller;import org.springframework.ui.model;import org.springframework.web.bind.annotation.getmapping;import org.springframework.web.bind.annotation.postmapping;import org.springframework.web.bind.annotation.requestparam;import javax.rvlet.http.httprvletrequest;import javax.rvlet.http.httpssion;@controllerpublic class ur { @autowired private urrvice urrvice; @autowired private onlinervice onlinervice; /** * @description : 登入显示 * @author : 南巷的花猫 * @date : 2021/11/23 14:02 */ @getmapping("/login") public string showlogin(){ return "ur/login"; } /** * @description : 获取登入信息 * @author : 南巷的花猫 * @date : 2021/11/23 14:03 */ @postmapping("/login") public string tlogin(@requestparam("name") string name, @requestparam("password") string password, model model, httpssion httpssion){ urentity urentity = urrvice.login(name, password); if (urentity != null){ if(onlinervice.geturmap(name) != null){ onlinervice.geturmap(name).invalidate(); } httpssion.tattribute("urinfo", urentity); onlinervice.turmap(name, httpssion); return "redirect:/"; }el { model.addattribute("eroor", "用户名或者密码出错"); return "ur/login"; } } @getmapping("/downline") public string downline(httpssion httpssion){ urentity urentity = (urentity) httpss大叶绿萝ion.getattribute("urinfo"); onlinervice.delecturmap(urentity.getname()); httpssion.invalidate(); return "redirect:/"; 中专是什么意思 }}
首页controller
package com.nx.j2ee.controller;import com.nx.j2ee.entity.urentity;import com.nx.j2ee.rvice.onlinervice;import org.springframework.beans.factory.annotation.autowired;import org.springframework.stereotype.controller;import org.springframework.ui.model;import org.springframework.web.bind.annotation.getmapping;import javax.rvlet.http.httprvletrequest;import javax.rvlet.http.httpssion;import java.util.map;import java.util.t;@controllerpublic class中考 成绩查询 index { @autowired private onlinervice onlinervice; private boolean lect = fal; @getmapping("/") public string showindex(model model, httpssion httpssion){ urentity urinfo = (urentity) httpssion.getattribute("urinfo"); if (urinfo != null){ this.lect = true; }el { this.lect = fal; } int onlinenum = onlinervice.shownum(); t<string> urt = onlinervice.showall().keyt(); model.addattribute("onlinenum", onlinenum); model.addattribute("urinfo", urinfo); model.addattribute("urt", urt); model.addattribute("lect", this.lect); return "home/index"; }}
html页面
<!doctype html><html xmlns="/d/file/titlepic/" xmlns:th="http://www.thymeleaf.org"><head> <meta chart="utf-8"> <link rel="stylesheet" href="/layui/css/layui.css"> <title>首页</title></head>&l梦的怒放歌词t;body><div class="layui-container"> <div> <ul class="layui-nav layui-bg-green" lay-filter=""> <li class="layui-nav-item"> <a href="">在线人数<span class="layui-badge" th:text="${onlinenum}"></span></a> </li> <li class="layui-nav-item"> <a th:href="@{/ptcour}">普通课程</a> </li> <li class="layui-nav-item"> <a th:href="@{/vipcour}">vip课程</a> </li> <li class="layui-nav-item"> <a th:href="@{/gzcour}">贵族课程</a> </li> <li class="layui-nav-item" style="float: right"> <a href="" th:if="${not lect}">游客</a> <a href="" th:if="${urinfo}" th:text="${urinfo.name}"></a> <dl class="layui-nav-child"> <dd th:if="${lect}"><span style="color: #2d6086">等级: </span><span style="color: #0c0c0c" th:text="${urinfo.gettest1()}"></span></dd> <dd><a href="javascript:;">修改信息</a></dd> <dd><a href="javascript:;">安全管理</a></dd> <dd><a th:href="@{/downline}" th:if="${lect}">下线</a></dd> <dd><a th:href="@{/login}" th:if="${not lect}">登入</a></dd> </dl> </li> </ul> </div> <div style="margin-top: 20px;padding: 0px 50px 0px 50px"> <div> <h3 style="color: #ac0d22">在线用户列表</h3> </div> <div th:each="urname:${urt}"> <p th:text="${urname}"></p> </div> </div></div><script src="/layui/layui.js"></script><script> layui.u(['layer', 'form'], function(){ var layer = layui.layer ,form = layui.form; layer.msg('追求极简'); });</script></body></html>
到此这篇关于springboot如何通过ssion实现单点登入的文章就介绍到这了,更多相关springbootssion单点登入内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!
本文发布于:2023-04-04 00:22:11,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/af2d638b34cfa5fa7304d97e99a9931c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:springboot如何通过session实现单点登入详解.doc
本文 PDF 下载地址:springboot如何通过session实现单点登入详解.pdf
留言与评论(共有 0 条评论) |