Struts - How do I clean up Session objects?

Discussions

Web tier: servlets, JSP, Web frameworks: Struts - How do I clean up Session objects?

  1. Struts - How do I clean up Session objects? (7 messages)

    I'm developing a Struts based application that will store JavaBeans in the Session. I read that objects stored in the Request scope are cleaned up automatically by the system. However, I haven't read anything about how to clean them up from the session scope.

    I'm expecting to have a "Logout" type operation where this will occur. Other than setting the object to null is there any thing else I need to do? Also, is there a way to handle these objects if a user just closes their web browser rather than logging out?

    Thanks in advance,
    Chris
  2. I'm developing a Struts based application that will store JavaBeans in the Session. I read that objects stored in the Request scope are cleaned up automatically by the system. However, I haven't read anything about how to clean them up from the session scope.I'm expecting to have a "Logout" type operation where this will occur. Other than setting the object to null is there any thing else I need to do? Also, is there a way to handle these objects if a user just closes their web browser rather than logging out?Thanks in advance,Chris
  3. Clean up is an every programmer's job. If you throw objects in session. You can do a once for all clean up when you invalidate the session. If you need to slectively remove the objects, you need to do session.removeAttibute("xxx");
    Hope this gives a lead in the direction where you want to go!
    Cheers
    Sekar
  4. Suggested Approach[ Go to top ]

    If you are going to make extensive use of the session, I would strongly recommend that you think about implementing some form of application infrastructure to handle/manage session data. This will ensure that Session data is tightly controlled by the application, which can alleviate memory issues, as well as possible side-effects.

    It could be organized by use-case. Take for example a multi-step wizard screen. Your design should specify what data will be placed in the session at each step, and what the valid values can be. A higher level entity (say a SessionManager class called on every request by the Struts Request Processor (which you can overload)) can examine the session and determine what use-case is being executed. If the user has changed use-case, then all the session data for any other use-cases should be removed.

    That is a high-level description of an approach I have taken. If you want to know more, post a reply, and I can send some more detail.

    As an aside, if the user closes their browser, you can run a tiny bit of JavaScript to detect this and send a logout message back to the server (this is no good if they just change the URL in the browser though). See my post at http://www.theserverside.com/discussions/thread.tss?thread_id=25891

    Regards,
     Trevor
  5. Suggested Approach[ Go to top ]

    I'm quite interested in your high-level approach. Would you mind to send more details about it

    Thanks
       Rolf
  6. Would you send more information about this, please. Thanks for your feedback.

    Chris
  7. Approach to Session Management[ Go to top ]

    All,
      I have posted a bit more detail and comment on my weblog, at http://trevorb.blog-city.com/.

    I am quite busy at the moment, but if people are interested, I can do up some code and make it part of an article or similar. If you want to see this, please post a comment to the weblog.

    Regards,
     Trevor
  8. Approach to Session Management[ Go to top ]

    I know its been long time, but i pumped into the same problem now- cleaning up the session objects.

    Trevor, the blog doesn't exist anymore. Just curious, do you have any other pointer? Thanks.