This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes using HttpSessionBindingListener interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "using HttpSessionBindingListener interface" Watch "using HttpSessionBindingListener interface" New topic
Author

using HttpSessionBindingListener interface

karim qazi
Greenhorn

Joined: Mar 22, 2001
Posts: 20
I am implementing HttpSessionBindingListener interface and I want to know when sessions are being created and dropped and then write something to a file when this event happens.
I thought all I had to do was implement this interface with the two methods valueBound() and valueUnbound() and sessions being created and dropped would automatically trigger these two methods to execute.
Any help would be appreciated.
Here is my code:
import java.io.*
public class Login extends User implements HttpSessionBindingListener {
private BufferedWriter log;

public Login() throws Exception {
super();
log = new BufferedWriter( new FileWriter("c:\\dvd_log.txt", true));
}

private void log(String data) throws IOException{
log.newLine(); // create new line to write to next time
log.write(data); // write input to file
log.flush();//clear buffer
}

public void valueBound(HttpSessionBindingEvent event){
try{
log("creating session...");
}catch(IOException e){
}
}

public void valueUnbound(HttpSessionBindingEvent event) {
try{
log("destroying session...");
}catch(IOException e){
}
}
}
[This message has been edited by karim qazi (edited March 27, 2001).]
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
ACcording to the JavaDoc,
valueBound(HttpSessionBindingEvent event)
"Notifies the object that it is being bound to a session and identifies the session."
Apparently the only purpose is to notify an object when it is being bound (added?) to an HttpSession.
The opposite for
valueUnbound(HttpSessionBindingEvent event)


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Sandeep Jain
Ranch Hand

Joined: Oct 25, 2000
Posts: 124
Hi ,
HttpSessionBindingListener is used for the purpose of binding an object to the session .It basically notifies "the object that it is being bound to a session and identifies the session.
say for example .
Say u r implementing the connection pool urself and u do not depend on the webserver( not the application server) in this case when the session is invalidated then the code has to be written in such a way as to the connection should return back to the pool .
here u will write the code in valueUnbound and valueBound functions .

------------------
Sandeep Jain


Try and Try Till u succeed<br /> <br />Sandeep Jain
karim qazi
Greenhorn

Joined: Mar 22, 2001
Posts: 20
why doesent my code work when i create a new session?
it should write to a log file i set up when creating or destroying a session.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using HttpSessionBindingListener interface
 
Similar Threads
what is HttpSessionBindingListener
Some issue with unBound. getting NullPointerException.
Difference b/w HttpSessionAttributesListener and HttpSessionBindingListener
Mock Exam question 55 - urgent
HttpSession timeout does not trigger an HttpSessionBindingEvent