Solved

Question for coreyit

Posted on 2002-04-04
2
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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