• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

Question for coreyit

Hi coreyit,

Few weeks ago, you helped me with a JSP session question. You mentioned a way to release any held resources when the session is about to die using HttpSessionBindingListener.  

Could you be a little more specific of how to use it? Or a simple example would be great.

Thanks a lot.

Sam
0
samantha
Asked:
samantha
1 Solution
 
kotanCommented:
Create an object which implement HttpSessionBindingListener. This object should be stored in the session.
Then, implement the valueBound() and valueUnBound() method. The valueUnbound() method will
be trigger if this object being unbound (This happen when the object is being replaced or session is invalid). In here, you can get the invalid session and delete away the record from the database.

public class BoundObj implements HttpSessionBindingListener {
  public BoundObj() {}
  public void valueBound(HttpSessionBindingEvent be) {
       // Will be trigger when this object being bound.
  }

  public void valueUnBound(HttpSessionBindingEvent be) {
      HttpSession hs = be.getSession();
      String userid = hs.getAttribute("userid");
      String sessionid = hs.getID();
      ....
      // Delete database record.
  }
}
At the time the user login which you create a new session, put the bound object in that session.
session.setAttribute("boundobj", new boundObj());
0
 
samanthaAuthor Commented:
kotan, thank you very much!

Sam
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now