获取当前session的方法

这个是直接获取session的工具类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class HttpSessionUtil {

public static HttpSession getHttpSession() {

HttpSession httpSession = null;

final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
httpSession = requestAttributes.getRequest().getSession();

return httpSession;

}

}