Search code examples
javajboss

Session Manegement using java


I am using jboss server. As of now my users getting logged out when my server bounces. On that time time I won't allow them to log out. How to manage this session even my server bounces.


Solution

  • Whenever you restart your server all user sessions will be lost. If you still want to keep user sessions then use cookies to maintain user sessions instead of thing like HttpSession.

    When user logged in keep its session and also maintain a cookie. When server restarts check if cookie present. If its there then allow user to access resources.

    You can set cookie as: For this you have to include jQuery.cookie.js file in your webpage. After user logged in set its cookie. It will remain set unless you remove it or after specific time. When you restart server all sessions will be destroyed but cookie will remain in browser. So if there is no session but cookie present in browser you can automatically logged in user and create its session again.

    $.cookie("test", 1);
    

    To delete:

    $.removeCookie("test");
    

    Additionally, to set a timeout of a certain number of days (10 here) on the cookie:

    $.cookie("test", 1, { expires : 10 });
    

    To read back the value of the cookie:

    var cookieValue = $.cookie("test");