思路说明:首先创建一个map,因为map是不可重复的键值对。使用登录用户的id作为key,当用户登录的时候,就产生一个session作为value。将其保存一起。此时改账号在别处登录的时候,会产生一个相当的key,但是不同的value。这是使用拦截器写代码清楚上一次的map。然后保存这一次的。这样已登录的用户就会被当前用户挤下来。
核心代码如下:
1.登录的时候创建map
ServletContext application=request.getSession().getServletContext();
String userIdSession = String.valueOf(user.get(0).getUserid());
@SuppressWarnings("unchecked")
Map<String, String> loginMap = (Map<String, String>)application.getAttribute("loginMap");
if(loginMap==null){
loginMap = new HashMap<String, String>();
}
loginMap.put(userIdSession,request.getSession().getId());
application.setAttribute("loginMap", loginMap);
2.写一个全局拦截器,实现Filter接口,在doFiter方法里面写如下代码
// 获取request
HttpServletRequest request=(HttpServletRequest)args0;
SessionInfo sessionInfo=SessionHelper.getSessionInfo(request);
SessionInfo adminSession = SessionHelper.getAdminSessionInfo(request);
HttpServletResponse response=(HttpServletResponse)args1;
String uri = request.getRequestURI();
if(uri.indexOf("login")!=-1 || uri.indexOf("changeImage")!=-1){
chain.doFilter(request, response);
return;
}
//前台同时只能一个账号在线
ServletContext application=request.getSession().getServletContext();
Map<String, String> loginMap = (Map<String, String>)application.getAttribute("loginMap");
if(loginMap!=null && !StringUtils.isNull(sessionInfo)){
for(String key:loginMap.keySet()) {
if (String.valueOf(sessionInfo.getUser().getUserid()).equals(key)) {
if(!request.getSession().getId().equals(loginMap.get(key))) {
String content_path = request.getContextPath();
request.removeAttribute("loginMap");
response.sendRedirect(content_path+"/visitor/users/login.do?flag=VALID");
System.out.println(content_path+"/visitor/users/login.do?flag=VALID");
return;
}
}
}
}
3.web.xml里面配置
<listener>
<description>spring监听器</description>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener </listener-class>
</listener>
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>SecurityInvalidate</filter-name>
<filter-class>com.project.filter.EmallAntiSqlInjectionfilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SecurityInvalidate</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
要了解内核socket需要先对内核socket的结构进行了解。其中比较重要的就是struct socket和struct sock两个结构体。每个socket数据结构都有一个sock数据结构成员,sock是对socket的扩充,两者一一对应,socket->sk指向对应的sock,sock->socket 指向对应的socket;socket和sock是同一事物的两个侧面,...
今天一起来练习栈、数组、递归、二分法吧,基本的小算法哦!!
#include &lt;stdio.h&gt;#include &lt;stdlib.h&gt;#define T 1#define F 0typedef int Status;typedef int ElemType;typedef struct StackNode//链式存储的结点{ ElemType data;//数据域 struct StackNode* nex...
配置文件package com.falun.conf;import org.springframework.context.annotation.Configuration;import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;i...
1.引入 spring-boot-starter-redis&lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-redis&lt;/artifactId&gt; &lt;/dependency&gt;# ...
垂直errorbar很容易实现,水平errorbar也经常用到,但网上很多方法都很复杂,在这里介绍一种相对简单的方法:实例:方法1:figure;err=data_std*ones(size(depth,2));errorbar(depth,data_av,err,'-r','linewidth',2) %先画垂直方向的errorbarhold on;plot(depth,data_av,'k-'...
6 Greenplum 对JSON的支持6.1 JSON概述JSON作为结构化的数据,目前越来越受到开发者的爱戴,它简单灵活易于理解。是作为储存数据的一种比较使用的一种格式,greenplum从5.0开始便很好的支持了JSON数据。 参考资料:https://hashrocket.com/blog/posts/faster-json-generation-with-postgres...
今年有两个时刻,让我有种众生皆苦的感觉。第一个是:安装师傅给安装空调的时候。父母以前在北方,我把他们接到广东养老。给他们买的是4房,需要5个空调。安装师傅从上午,一直安装到晚上,中途完全没有吃饭。就给他们喝了点水,给饭也不吃。就说都装完了回去吃,都饿习惯了。看到一身汗,不停的忙,真的蛮不容易的。我自己买的房,在二十多层。有个空调外机有问题,安装师傅需要拆护栏,拆纱窗,再拆窗户。有一个安装师傅需要高空作业,爬到窗户外,另一个师傅在屋里。在屋里的安装师傅把外机搬出窗户,看那个师傅估计也就一米六,空调外机一
curl_setopt($curl, CURLOPT_HTTPHEADER, array(‘Content-Type: application/x-www-form-urlencoded’));方式from-data试发送的数据用的是array格式,而方式为 x-www-form-urlencoded 时需要用key=value&key=value的格式发送,发送的是string型的数据。from-data数据的为:data=[′name′=>′xiaoming′,′sex′
&lt;!-- 引入jquery文件 --&gt; &lt;script type="text/javascript" src="./js/jquery-1.4.4.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; /**第一步加载html页面*/
问题AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message解决方案:https://www.cnblogs...._1671465600
ArrayList去除集合中字符串的重复值public static ArrayList getSingle(ArrayList list) {ArrayList newList = new ArrayList();//创建一个新集合Iterator it = list.iterator();//获取迭代器while(it.hasNext()) {//判断老集合中是否...