我正在使用spring框架,这是我用来修复HttpSession
对象的代码:
ServletRequestAttributes attr;
try {
attr = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
} catch (Exception e) { }
HttpSession session = attr.getRequest().getSession(false);
Holder类以 线程绑定 的形式公开Web请求 RequestAttributes对象。
因此,在容器处理请求所创建的线程之外不会看到它。有没有办法在某个子线程中检索会话?
答案 0 :(得分:2)
不,没有。在Servlet API中,会话是请求对象的属性。因此,如果您没有请求,您会检索多个现有会话中的哪一个?