Solved

Question for coreyit

Posted on 2002-04-04
2
182 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
In this increasingly digital world, security hacks are no longer just a threat, but a reality. As we've witnessed with Target's big identity hack 2013, Heartbleed in 2015, and now Cloudbleed, companies and their leaders need to prepare for the unthi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 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