Solved

Question for coreyit

Posted on 2002-04-04
2
179 Views
Last Modified: 2010-04-01
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
Comment
Question by:samantha
2 Comments
 
LVL 6

Accepted Solution

by:
kotan earned 200 total points
ID: 6920063
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
 

Author Comment

by:samantha
ID: 6921736
kotan, thank you very much!

Sam
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now