Solved

Question for coreyit

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JspWriter.write() and JspWriter.print() 4 81
Need to view directory list in apache/tomcat 9 109
rebasing and merging used in SCM 1 66
print map entry 34 54
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

912 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

26 Experts available now in Live!

Get 1:1 Help Now