Currently, I am setting up user sessions on Java (with JSP on Struts 2 Framework) with the following code:
HttpSession session = request.getSession(true);
SessionBean sessionBean = new SessionBean();
session.setMaxInactiveInterval(604800);
sessionBean.setUserBean(userBean);
session.setAttribute("sessionBean", sessionBean);
This session is terminated only when the user explicitly logs out with the following code:
HttpSession session = request.getSession(true);
session.removeAttribute("sessionBean");
While sessions automatically expire after 1 week (604800 seconds) of user inactivity.
The above works all fine and dandy on desktop browsers. However, on mobile browsers (observed on iPhone Safari and Android's default browser), the session expires after the page is idle for 30 minutes or more.
I just replicated the problem with the following steps:
- Opened the page on iPhone Safari, left the page idle and closed iPhone Safari (with it still running in the background).
- Reopened iPhone Safari 30 minutes later.
- The page refreshed and when it did so, my session was lost.
How do I preserve sessions on mobile such that the user stays logged in unless they explicitly logout (or their session expires within the standard 7 days of inactivity)?
Thanks in advance!