Keep a session alive for an indefinite amount of time

后端 未结 2 584
醉酒成梦
醉酒成梦 2020-12-28 11:33

Is there a way to keep a page\'s session active without resorting to sending the state to the client? I\'m not able to set the STATE_SAVING_METHOD to cli

2条回答
  •  情书的邮戳
    2020-12-28 11:56

    BalusC's answer helped me to meet this requirement in my app, but since I'm using PrimeFaces, I wanted to share how BalusC's answer inspired the code i'm using to do this.

    xhtml page

    
    

    bean

    public void keepUserSessionAlive() {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        request.getSession();
    }
    

    as always, thank you, BalusC!

    EDIT: An enduser put this to the test this morning, and it is working great! my app usually forces session timeout 15 minutes after full page refresh (redirect to sessionExpired.xhtml via meta refresh based on session.maxInactiveInterval and session timeout value in web.xml); if user is on one page doing a bunch of AJAX requests, session will timeout, since AJAX != full page refresh, but this code allowed enduser to 'keep session alive' while enduser was on payroll page in the app, and session stayed alive for 1 to 2 hours! :)

提交回复
热议问题