【发布时间】:2014-10-24 21:31:25
【问题描述】:
我正在使用
FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
,有什么方法可以获取客户端发出与同一会话相关联的请求的最后访问时间,就像
Session.getLastAccessedTime()
?截至目前,我可以找到任何方法。有什么建议吗?谢谢!
【问题讨论】:
标签: jsf session httpsession
我正在使用
FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
,有什么方法可以获取客户端发出与同一会话相关联的请求的最后访问时间,就像
Session.getLastAccessedTime()
?截至目前,我可以找到任何方法。有什么建议吗?谢谢!
【问题讨论】:
标签: jsf session httpsession
从external context中获取当前的HttpSession:
HttpSession session = (HttpSession)FacesContext
.getCurrentInstance().getExternalContext.getSession(false);
然后获取last accessed time:
if (session != null)
long ms = session.getLastAccesedTime();
else
System.out.println("There's no session created for the current user");
您可以稍后将其转换为Date:
Date d = new Date(ms);
【讨论】:
ec.getSession(false) 并在之后使用null 检查。如果没有当前会话,只需将时间设置为某个负的预定义值。