【问题标题】:Get the last accessed time a client sends a request using the same session in jsf?获取客户端使用jsf中的同一会话发送请求的最后访问时间?
【发布时间】:2014-10-24 21:31:25
【问题描述】:

我正在使用

FacesContext.getCurrentInstance().getExternalContext().getSessionMap()

,有什么方法可以获取客户端发出与同一会话相关联的请求的最后访问时间,就像

Session.getLastAccessedTime()

?截至目前,我可以找到任何方法。有什么建议吗?谢谢!

【问题讨论】:

    标签: jsf session httpsession


    【解决方案1】:

    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);
    

    【讨论】:

    • @Xtreme 我认为不应该在上述要求下创建新会话。所以我宁愿打电话给ec.getSession(false) 并在之后使用null 检查。如果没有当前会话,只需将时间设置为某个负的预定义值。
    猜你喜欢
    • 2017-12-06
    • 2016-12-02
    • 2012-09-01
    • 2019-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-25
    相关资源
    最近更新 更多